Changing the outerHTML of an Iframe

D

David Virgil Hobbs

I discovered how to write out the inner HTML of the contents of an
Iframe; I want to know how to write out the outerHTML of the contents
of an Iframe.

frames['iframeid'].document.body.innerHTML allows me to read the inner
HTML of the contents of an iframe and also allows me to write out the
inner HTML of the contents of an iframe.

However using frames['iframeid'].document.body.innerHTML I am only able
to change, in the contents of the iframe, the code in between and
including the body tags; I am not able to change the code above the
body tag such as what is in the head section and what is in the html
tag.

The problem is, that other maneuvers that allow me to read the contents
of an iframe, do NOT allow me to write out the contents of the iframe.
These are:

frames['framid'].document.body.outerText
frames['framid'].document.body.innerText
frames['framid'].document.documentElement.outerHTML

The problem persists if the page originally loaded into the iframe
contains no code.

This looks like an unpredictable inconsistency of the type that makes
Javascript a language to be learned through experimentation. Or is
there some documentation somewhere that lists the read/write abilities
of such lines of code?
 
D

Danny

Well, outerHTML is IE only for one, and from msnd kb ->

Applies To
A, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BGSOUND, BIG, BLOCKQUOTE,
BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CUSTOM, DD,
DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM,
FRAMESET, hn, HR, HTML Comment, HTML, I, IFRAME, IMG, INPUT
type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden,
INPUT type=image, INPUT type=password, INPUT type=radio, INPUT
type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL,
LEGEND, LI, LISTING, MAP, MARQUEE, MENU, nextID, NOBR, OBJECT, OL, P,
PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SELECT, SMALL, SPAN, STRIKE,
STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR,
TT, U, UL, VAR, WBR, XMP
----------------------------------
The property is read/write for all objects except the following, for
which it is read-only: CAPTION, COL, COLGROUP, FRAMESET, HTML, TBODY,
TD, TFOOT, TH, THEAD, TR. The property has no default value.

It doesn't include BODY.

Danny
 
N

Neredbojias

To further the education of mankind, "David Virgil Hobbs"
I discovered how to write out the inner HTML of the contents of an
Iframe; I want to know how to write out the outerHTML of the contents
of an Iframe.

The last time I checked, outerHTML didn't work in most of my browsers.
 
D

Daniel Kirsch

David said:
However using frames['iframeid'].document.body.innerHTML I am only able
to change, in the contents of the iframe, the code in between and
including the body tags; I am not able to change the code above the
body tag such as what is in the head section and what is in the html
tag.

Instead of using innerHTML you may create a new document and use
document.write()

You may also access the head element by using DOM methods like:
var htmlElm = document.documentElement;
var headElm = htmlElm.getElementsByTagName("head")[0];

But what are you trying to do in the head?
To change the title, you may use
document.title = "foo";

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top