Get content of Iframe?

P

Philipp

How can I get the content of another Iframe? (Provided it's the same
domain.)

E.g. something like the following, except it doesn't work...
var frame = document.getElementById("myframe");
alert(frame.innerHTML);

thanks!
 
E

Evertjan.

Philipp wrote on 20 dec 2007 in comp.lang.javascript:
How can I get the content of another Iframe? (Provided it's the same
domain.)

E.g. something like the following, except it doesn't work...
var frame = document.getElementById("myframe");
alert(frame.innerHTML);

IE7 and FF2:

<script type='text/javascript'>

function a(){
var iframe = document.getElementById("myframe");
alert(iframe.contentWindow.document.body.innerHTML);
}

</script>

<iframe id ='myframe' src='base64.html'></iframe>

<button onclick='a()'>get</button>
 
B

Bart Van der Donck

Evertjan. said:
Philipp wrote on 20 dec 2007 in comp.lang.javascript:
IE7 and FF2:

<script type='text/javascript'>

function a(){
var iframe = document.getElementById("myframe");
alert(iframe.contentWindow.document.body.innerHTML);
}

</script>

<iframe id ='myframe' src='base64.html'></iframe>
<button onclick='a()'>get</button>

This would indeed return the HTML of <body/>, but the whole content is
more than that.

http://www.jibbering.com/faq/#FAQ4_38
 
E

Evertjan.

Bart Van der Donck wrote on 20 dec 2007 in comp.lang.javascript:
This would indeed return the HTML of <body/>, but the whole content is
more than that.

The OP did not ask for the whole content,
perhaps he asked for nothing but the content. ;-)

That calls for reloading of the content from the server,
and that does not have to be the same content.
[For instance if the server shows a sessionless hit counter]
 
B

Bart Van der Donck

Evertjan. said:
Bart Van der Donck wrote on 20 dec 2007 in comp.lang.javascript:



The OP did not ask for the whole content,
perhaps he asked for nothing but the content. ;-)

It is incorrect to speak about the innerHTML of <body> as if that were
the content of a HTML page.
 
E

Evertjan.

Bart Van der Donck wrote on 22 dec 2007 in comp.lang.javascript:
It is incorrect to speak about the innerHTML of <body> as if that were
the content of a HTML page.

Perhaps it is, but my example was only, yes, you guessed it, an example.

You are seeing a problem where there is none.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top