iframes are not supported by Netscape 4.
location.href in an iframe to change the page in the iframe
does not work in Explorer 4 and 5.0 on Windows and Opera 5 and 6.
On this page I give a short overview of accessing iframes from the page they’re on. Not surprisingly, there are some browser considerations.
An iframe is an inline frame, a frame that, while containing a completely separate page with its own URL, is nonetheless placed inside another HTML page. This gives very nice possibilities in web design. The problem is to access the iframe, for instance to load a new page into it. This page explains how to do it.
The fundamental question is whether the iframe is seen as a frame or as an object.
top.frames.framesand such). Does the iframe fit into this frame hierarchy?
srcproperty? In that case we have to use a standard DOM call (like
document.getElementById('theiframe')) to access it.
In general browsers allow both views on 'real' (hard-coded) iframes, but generated iframes cannot be accessed as frames.
The most important rule is to give any iframe you create a
even if you also use an
<iframe src="iframe_page1.html" id="testiframe" name="testiframe"></iframe>
Most browsers need the
name attribute to make the iframe part of the frame hierarchy.
Some browsers (notably Mozilla) need the
id to make the iframe accessible as an
object. By assigning both attributes to the iframe you keep your options open. But
is far more important than
Either you access the iframe as an object and change its
or you access the iframe as a frame and change its
document.getElementById('iframe_id').src = 'newpage.html'; frames['iframe_name'].location.href = 'newpage.html';
The frame syntax is slightly preferable because Opera 6 supports it but not the object syntax.
So for a complete cross–browser experience you should give the iframe a
name and use the
syntax. As far as I know this always works.
Accessing the document inside the iframe is quite simple, provided you use the
attribute. To count the number of links in the document in the iframe, do
When you generate an iframe through the W3C DOM the iframe is not immediately
entered into the
frames array, though, and the
will not work right away. The browser needs a little time before the iframe turns up in the array, time during
which no script may run.
document.getElementById('testiframe').src syntax works fine in all circumstances.
target attribute of a link doesn't work either with generated iframes, except in Opera,
even though I gave my generated iframe both a
name and an
The lack of
as much of a problem.
<iframe src="iframe_page1.html" id="testiframe2"></iframe>
A curious Explorer 6 only bug:
When you change the text size through the View menu, text sizes in iframes are correctly changed. However, this browser does not change the line breaks in the original text, so that part of the text may become invisible, or line breaks may occur while the line could still hold another word.