469,271 Members | 1,049 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Writing to an IFRAME's innerHTML

How do I set the innerHTML property of a contained IFRAME ?

Many thanks in advance,

Aaron
Aug 26 '08 #1
22 9039
"Aaron Gray" <an********@gmail.comwrote in message
news:6h************@mid.individual.net...
How do I set the innerHTML property of a contained IFRAME ?
I got

window.frames["results"].document.body.innerHTML

This works on FF and Opera, but not on IE.

Aaron


Aug 26 '08 #2
"Aaron Gray" <an********@gmail.comwrites:
"Aaron Gray" <an********@gmail.comwrote in message
news:6h************@mid.individual.net...
>How do I set the innerHTML property of a contained IFRAME ?

I got

window.frames["results"].document.body.innerHTML

This works on FF and Opera, but not on IE.
IIRC, window.frames["results"].document.contentWindow.document.body.innerHTML

should work on IE.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Aug 26 '08 #3

"Joost Diepenmaat" <jo***@zeekat.nlwrote in message
news:87************@zeekat.nl...
"Aaron Gray" <an********@gmail.comwrites:
>"Aaron Gray" <an********@gmail.comwrote in message
news:6h************@mid.individual.net...
>>How do I set the innerHTML property of a contained IFRAME ?

I got

window.frames["results"].document.body.innerHTML

This works on FF and Opera, but not on IE.

IIRC,
window.frames["results"].document.contentWindow.document.body.innerHTML

should work on IE.
window.frames["result"].document.contentWindow.document

Is saying the above is null or not an object.

I have an IFRAME thus :-

<iframe id="result" name="result"></iframe>

Confused, they sure do make this stuff easy !

Aaron
Aug 26 '08 #4
"Aaron Gray" <an********@gmail.comwrites:
"Joost Diepenmaat" <jo***@zeekat.nlwrote in message
news:87************@zeekat.nl...
>"Aaron Gray" <an********@gmail.comwrites:
>>"Aaron Gray" <an********@gmail.comwrote in message
news:6h************@mid.individual.net...
How do I set the innerHTML property of a contained IFRAME ?

I got

window.frames["results"].document.body.innerHTML

This works on FF and Opera, but not on IE.

IIRC,
window.frames["results"].document.contentWindow.document.body.innerHTML

should work on IE.

window.frames["result"].document.contentWindow.document

Is saying the above is null or not an object.
http://msdn.microsoft.com/en-us/libr...92(VS.85).aspx

You may want to leave out the first "document".
Confused, they sure do make this stuff easy !
Of course they don't.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Aug 26 '08 #5
"Joost Diepenmaat" <jo***@zeekat.nlwrote in message
news:87************@zeekat.nl...
"Aaron Gray" <an********@gmail.comwrites:
>"Joost Diepenmaat" <jo***@zeekat.nlwrote in message
news:87************@zeekat.nl...
>>"Aaron Gray" <an********@gmail.comwrites:

"Aaron Gray" <an********@gmail.comwrote in message
news:6h************@mid.individual.net...
How do I set the innerHTML property of a contained IFRAME ?

I got

window.frames["results"].document.body.innerHTML

This works on FF and Opera, but not on IE.
IIRC,
window.frames["results"].document.contentWindow.document.body.innerHTML

should work on IE.

window.frames["result"].document.contentWindow.document

Is saying the above is null or not an object.

http://msdn.microsoft.com/en-us/libr...92(VS.85).aspx
Wow, great documentation, looks really old stuff.
You may want to leave out the first "document".
Tried that :-

window.frames.result.contentWindow.document is null or not an object

Again
>Confused, they sure do make this stuff easy !

Of course they don't.
Cant find any good documentation on it, tried W3C standard approach too.

Aaron
Aug 26 '08 #6
"Aaron Gray" <an********@gmail.comwrites:
window.frames.result.contentWindow.document is null or not an object
In the posts above you refer to

window.frames.results

with an S at the end.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Aug 26 '08 #7
"Joost Diepenmaat" <jo***@zeekat.nlwrote in message
news:87************@zeekat.nl...
"Aaron Gray" <an********@gmail.comwrites:
> window.frames.result.contentWindow.document is null or not an object

In the posts above you refer to

window.frames.results

with an S at the end.
Yes, its not that, sorry to confuse.

I am wondering whether it was banned as a secuity problem.

Aaron
Aug 26 '08 #8
On Aug 26, 5:38*pm, "Aaron Gray" <ang.use...@gmail.comwrote:
"Joost Diepenmaat" <jo...@zeekat.nlwrote in message

news:87************@zeekat.nl...
"Aaron Gray" <ang.use...@gmail.comwrites:
* * window.frames.result.contentWindow.document is null or not an object
In the posts above you refer to
window.frames.results
with an S at the end.

Yes, its not that, sorry to confuse.

I am wondering whether it was banned as a secuity problem.

Aaron
If the document in the iframe is on another site it will throw an
exception. Security issue.
If you catch the exception and show it in an alert box, it will say
something like:
"Error: Permission denied to get property Window.document"

I have recently accessed an iframe like so:

frames['name_of_the_frame'].document

here is another article on the topic:
http://xkr.us/articles/dom/iframe-document/

As to the innerHTML, can I ask why you want this? I'm pretty certain
that if you are trying to manipulate the document in the iframe, you
don't want the innerHTML.

Here is where I recently piddled around with iframes:
http://polisick.com/crossdomainformattempt.php
Aug 26 '08 #9
"Doug Gunnoe" <do********@gmail.comwrote in message
news:7f**********************************@59g2000h sb.googlegroups.com...
>
here is another article on the topic:
http://xkr.us/articles/dom/iframe-document/
-
Thats great, it works when on a button or on body onload, but not executed
as inline javascript.

That was my problem !
>As to the innerHTML, can I ask why you want this? I'm pretty certain
that if you are trying to manipulate the document in the iframe, you
don't want the innerHTML.
For test purposes when testing AJAX.

Thanks that helped alot !:)

Aaron

Aug 27 '08 #10
Its now a two liner :-

//
// getFrameDoc() - get the document for a frame window
//
// Note: this must be executed via body.onload or later
//

function getFrameDoc( frame)
{
var doc = (frame.contentWindow || frame.contentDocument);
return doc.document || doc
}

Aaron

Aug 27 '08 #11
"Aaron Gray" <an********@gmail.comwrote in message
news:6h************@mid.individual.net...
Its now a two liner :-

//
// getFrameDoc() - get the document for a frame window
//
// Note: this must be executed via body.onload or later
//

function getFrameDoc( frame)
{
var doc = (frame.contentWindow || frame.contentDocument);
return doc.document || doc
}
I have also found this will only work for a frame got by id, not from
window.frames[] :-

var framedoc = getFrameDoc( document.getElementById('myframe'));

works, where :-

var framedoc = getFrameDoc( window.frames["myframe"])

throws an error.

Anyone throw some light on this ?

Thanks,

Aaron

Aug 27 '08 #12
Aaron Gray wrote:
"Aaron Gray" <an********@gmail.comwrote [...]:
Please do not write attribution novels, see <http://insideoe.com/>
(Windows Mail is Outlook Express's successor).
>function getFrameDoc( frame)
{
var doc = (frame.contentWindow || frame.contentDocument);
return doc.document || doc
}

I have also found this will only work for a frame got by id, not from
window.frames[] :-

var framedoc = getFrameDoc( document.getElementById('myframe'));

works, where :-

var framedoc = getFrameDoc( window.frames["myframe"])

throws an error.
You could be a bit more specific. Which error, on which line, in which
runtime environment?
PointedEars

P.S.: Firebug 1.2.0 (final) has been released! :)
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 27 '08 #13

"Thomas 'PointedEars' Lahn" <Po*********@web.dewrote in message
news:48**************@PointedEars.de...
Aaron Gray wrote:
>"Aaron Gray" <an********@gmail.comwrote [...]:

Please do not write attribution novels, see <http://insideoe.com/>
(Windows Mail is Outlook Express's successor).
I do not understand please elaborate.
>>function getFrameDoc( frame)
{
var doc = (frame.contentWindow || frame.contentDocument);
return doc.document || doc
}

I have also found this will only work for a frame got by id, not from
window.frames[] :-

var framedoc = getFrameDoc( document.getElementById('myframe'));

works, where :-

var framedoc = getFrameDoc( window.frames["myframe"])

throws an error.

You could be a bit more specific. Which error, on which line, in which
runtime environment?
IE7 the second line.

By Id :-

http://www.aarongray.org/Test/JavaSc...ame-test2.html

By window.frames[]

http://www.aarongray.org/Test/JavaSc...ame-test3.html

Its probably something very simple I am not familuar with yet.

Aaron

Aug 27 '08 #14
"Aaron Gray" <an********@gmail.comwrites:
var framedoc = getFrameDoc( document.getElementById('myframe'));

works, where :-

var framedoc = getFrameDoc( window.frames["myframe"])

throws an error.
Without having read the rest of the thread, so I don't know what
getFrameDoc does, the important difference is likely to be that
document.getElementById('myframe')
returns the "iframe" element that is part of this document's DOM
tree, whereas
window.frames["myframe"]
evaluates to the window object of the page that is the content
of the frame.
I.e., one is a DOM element object in the scope of the current page,
the other is the window object of the nested page. They are quite
different objects. You probably want the latter.

/L
-
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 27 '08 #15
SAM
Aaron Gray a écrit :
>
Tried that :-

window.frames.result.contentWindow.document is null or not an object
for sure : there is NO document in your iframe !
(no src)

does : window.frames.results
is same as : window.frames['results']
or : document.results
or : parent.results

Try with an html file (with empty body?) opened in your iframe

or/and (only because you've a name in your iframe) perhaps :
parent.results.contentWindow.document.body.innerHT ML
(not tested)

If in first step you open a file (*of same domain*) in your iframe,
probably you'll have no more problem of security.

--
sm
Aug 27 '08 #16
Lasse Reichstein Nielsen wrote:
"Aaron Gray" <an********@gmail.comwrites:
> var framedoc = getFrameDoc( document.getElementById('myframe'));

works, where :-

var framedoc = getFrameDoc( window.frames["myframe"])

throws an error.

Without having read the rest of the thread, so I don't know what
getFrameDoc does, [...]
the declaration was right above that, in the part that you snipped :)
Regards,

PointedEars

P.S.:
<***@hotpop.com>: host mx1.hotpop.com[38.113.3.81] said:
550 <***@hotpop.com>:
Recipient address rejected: Account closed due to inactivity.
No forwarding information is available. (in reply to RCPT TO command)

And your signature delimiter is borken; must be "--<SP><CR><LF>":
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Aug 27 '08 #17
SAM
Aaron Gray a écrit :
>
var framedoc = getFrameDoc( window.frames["myframe"])

throws an error.
Probably better with (if named iframe) :

var framedoc = getFrameDoc( parent.myframe );

or :

var framedoc = getFrameDoc( top.myframe );

Perhaps :
var framedoc = getFrameDoc( window.frames["myframe"])
Anyway it is much better to use ID
(with name that will no more work if the main page is itself in a frame)
Here is a code working in my Firefox 3 and IE 6:
<http://cjoint.com/data/iBmXw4PQVM_ecrit_frame.htm>

Extracts :

<script type="text/javascript">
function scrib(frameNameOrId, texto) {
var f = document.getElementById(frameNameOrId)?
document.getElementById(frameNameOrId) :
top[frameNameOrId];
f = (f.contentWindow || f.contentDocument || f);
f = f.document || f;
f.body.innerHTML = texto;
}
</script>

<iframe name="results" border=1></iframe>
<iframe id="result" border=1></iframe>
<p><a href="javascript:scrib('results','hello world')">test by name</a>
<p><a href="javascript:scrib('result','hello world')">test by id</a>

--
sm
Aug 27 '08 #18
Thomas 'PointedEars' Lahn wrote:
And your signature delimiter is borken; must be "--<SP><CR><LF>":
Would somebody explain me the word 'borken'? Google gives this answer in
english to the query define:borken

Borken is a Kreis (district) in the northwestern part of North
Rhine-Westphalia, Germany. Neighboring districts are Bentheim, Steinfurt,
Coesfeld ...
en.wikipedia.org/wiki/Borken (district)

I would otherwise think this means 'broken', but when it has been used at
least tens of times by a person, who admirably thoroughly corrects every
detail, then there is obviously a good reason to use this word 'borken'.
Aug 27 '08 #19
"optimistx" <op*************@poistahotmail.comwrites:
Would somebody explain me the word 'borken'? Google gives this answer in
english to the query define:borken
http://www.urbandictionary.com/define.php?term=borken

Probably related to "borked".

/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 27 '08 #20
Lasse Reichstein Nielsen wrote on 27 aug 2008 in comp.lang.javascript:
"optimistx" <op*************@poistahotmail.comwrites:
>Would somebody explain me the word 'borken'? Google gives this answer in
english to the query define:borken

http://www.urbandictionary.com/define.php?term=borken

Probably related to "borked".
1: Bork (IPA : børk)is the official language of Sweden, stolen by Norway as
of Friday 13. August, 1905. Closely related to the dialect of Japanese as
spoken by the aboriginal Ainu people, Bork is characterised by its
remarkably limited number of phonemes and ridiculously short alphabet.
<http://uncyclopedia.org/wiki/Bork>

2: Possibly derived from a word used repeatedly by the Swedish Chef of the
Muppets. In various skits, the Chef often repeats the phrase bork, bork,
bork. The word may refer to the often-failed experiments in the Chef's
cooking adventures.
<http://en.wiktionary.org/wiki/Bork>

3: a no no:
<http://www.youtube.com/watch?v=jc_UCc8EQcQ>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 27 '08 #21
Evertjan. wrote:
Lasse Reichstein Nielsen wrote on 27 aug 2008 in comp.lang.javascript:
>"optimistx" <op*************@poistahotmail.comwrites:
>>Would somebody explain me the word 'borken'? Google gives this
answer in english to the query define:borken

http://www.urbandictionary.com/define.php?term=borken

Probably related to "borked".

1: Bork (IPA : børk)is the official language of Sweden, stolen by
Norway as of Friday 13. August, 1905. Closely related to the dialect
of Japanese as spoken by the aboriginal Ainu people, Bork is
characterised by its remarkably limited number of phonemes and
ridiculously short alphabet. <http://uncyclopedia.org/wiki/Bork>

2: Possibly derived from a word used repeatedly by the Swedish Chef
of the Muppets. In various skits, the Chef often repeats the phrase
bork, bork, bork. The word may refer to the often-failed experiments
in the Chef's cooking adventures.
<http://en.wiktionary.org/wiki/Bork>

3: a no no:
<http://www.youtube.com/watch?v=jc_UCc8EQcQ>
Oekee palajo inehmoelle kiitoksija näestä selevityksistä. On nii kivvoo ku
suap tiällä käöttöö muinaesta puhetta nii ku borken.
Aug 27 '08 #22
optimistx wrote on 27 aug 2008 in comp.lang.javascript:
Evertjan. wrote:
>Lasse Reichstein Nielsen wrote on 27 aug 2008 in
comp.lang.javascript:
>>"optimistx" <op*************@poistahotmail.comwrites:

Would somebody explain me the word 'borken'? Google gives this
answer in english to the query define:borken

http://www.urbandictionary.com/define.php?term=borken

Probably related to "borked".

1: Bork (IPA : børk)is the official language of Sweden, stolen by
Norway as of Friday 13. August, 1905. Closely related to the dialect
of Japanese as spoken by the aboriginal Ainu people, Bork is
characterised by its remarkably limited number of phonemes and
ridiculously short alphabet. <http://uncyclopedia.org/wiki/Bork>

2: Possibly derived from a word used repeatedly by the Swedish Chef
of the Muppets. In various skits, the Chef often repeats the phrase
bork, bork, bork. The word may refer to the often-failed experiments
in the Chef's cooking adventures.
<http://en.wiktionary.org/wiki/Bork>

3: a no no:
<http://www.youtube.com/watch?v=jc_UCc8EQcQ>

Oekee palajo inehmoelle kiitoksija näestä selevityksistä. On nii
kivvoo ku suap tiällä käöttöö muinaesta puhetta nii ku borken.
OK, moet in dat nu allemaal opeens zo maar optimistisch begrijpen,
even though Borken, Germany is just 40 km due South of where I live??

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 27 '08 #23

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Reply Via Newsgroup | last post: by
7 posts views Thread by Christopher J. Hahn | last post: by
4 posts views Thread by L Anthony Johnson | last post: by
14 posts views Thread by Aaron Gray | last post: by
8 posts views Thread by Henrik Stidsen | last post: by
4 posts views Thread by Yansky | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.