[thelist] [javascript] referencing an iframe from a child window
Tom Dell'Aringa
pixelmech at yahoo.com
Mon Sep 29 21:48:17 CDT 2003
--- Paul Bennett <paul at teltest.com> wrote:
> 'Volters, I want to reference an iframe in a parent window from a
> function in a child window.
>
> I can reference the DOM of the parent window fine using things like
> window.parent.document .. but from what I can see an Iframe is
> treated as a seperate document to the document it is contained in.
> I can reference it from the parent document (by using it's id) but
> don't seem to be able to do the same from the child window.
> Can anyone give me any pointers on how to reference it?
Paul,
Its a bit hard to glean the structure of what you have without a
clearer explanation - but an iFrame is referenced just like any other
frame, so you can use the frames[] array.
So if you have this frameset:
<html>
<frameset rows="50%,*">
<frame name="upper" src="up.html" marginwidth="10"
marginheight="10" scrolling="auto" frameborder="0">
<frame name="lower" src="down.html" marginwidth="10"
marginheight="10" scrolling="auto" frameborder="0">
</frameset>
</html>
And "upper" has the iframe "x" inside of it, you can access it from a
function in "lower" like so:
targ =
parent.window.frames['upper'].window.frames['x'].document.body;
targ.innerHTML = "<b>hi!</b>";
This is quick and dirty and I'm not sure exactly what you want to do
- but it works. Post more info and I'll be glad to help more.
HTH
Tom
More information about the thelist
mailing list