iframe

J

Jeff Thies

I have an iframe (IE5):

<iframe name="frame1" id="frame1" src="some_source">test</iframe>

that test appears outside the iframe, the src contents are in the iframe
though

I'd like to read the iframe.

var frame1=document.getElementById('frame1').innerHTML;

What I get is "test", not what the contents of the iframe actually is.

What have I done wrong?

Jeff
 
L

Lasse Reichstein Nielsen

Jeff Thies said:
I have an iframe (IE5):

<iframe name="frame1" id="frame1" src="some_source">test</iframe>

that test appears outside the iframe, the src contents are in the iframe
though

I'd like to read the iframe.

var frame1=document.getElementById('frame1').innerHTML;

What I get is "test", not what the contents of the iframe actually is.

What have I done wrong?

You want to access the content page in the frame. That is a completely
different page, so its HTML is not part of the iframe element on this
page.

What you can do is either:

var frame1=document.getElementById('frame1');
var iframeDocument = frame1.contentWindow ? frame1.contentWindow.document
: frame1.contentDocument;
var root = iframeDocument.documentElement || iframeDocument.body;
var HTML = root.innerHTML;

or

var frame1Document = frames['frame1'].document;
var root = iframeDocument.documentElement || iframeDocument.body;
var HTML = root.innerHTML;

/L
 

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,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top