Re: Accessing Nested IFrame's Parent ID and Names

B

bruce barker

the name and id assigned to frame are only known to its parent (as its the
name of a child frame), as there is no html element in the frame source that
represents the window, the windows id and name are always null.

<html>
<body id=mainBody>
<!--
local javascript can refer to the following frame by the id, or using
the frames collection. but javascript in the frame
will not see this name, because its only know here. ex:
window.frames['foo'].name will return null.
-->
<iframe name=foo id=foo>
</iframe>
</body>
</html>

you can put a name or id on the body and check that.

window.parent.document.body.name;

-- bruce (sqlwork.com)



MLibby said:
How can I access an IFrame's id or name from within a child IFrame?

My application can have nested IFrames (one IFrame exists within another).
Each child IFrame needs to access its parent IFrame's javascipt methods.
However before it attempts to access the parent IFrame method it needs to
know if its parent is truley an IFrame and the correct IFrame.
I tried assigning each IFrame an ID and then having each IFrame check its
parent IFrame's ID however, I found that child IFrame can't retrieve thier
parent's IFrame ID. For example window.parent.id should return the name of
the IFrame's parent but for some reason the id is always null. The same is
true for an IFrame's name.
I also tried seing if the child's parent contains a method and then call
that method in hopes of retriving its IFrame ID, ie.
 
G

Guest

Thanks Bruce,

I believe assigning a name to an abritary variable inside of the frame and then checking it from the child frame will work. Thanks for you help,
Mike

--
mcp, mcse, mcsd, mcad.net, mcsd.net


bruce barker said:
the name and id assigned to frame are only known to its parent (as its the
name of a child frame), as there is no html element in the frame source that
represents the window, the windows id and name are always null.

<html>
<body id=mainBody>
<!--
local javascript can refer to the following frame by the id, or using
the frames collection. but javascript in the frame
will not see this name, because its only know here. ex:
window.frames['foo'].name will return null.
-->
<iframe name=foo id=foo>
</iframe>
</body>
</html>

you can put a name or id on the body and check that.

window.parent.document.body.name;

-- bruce (sqlwork.com)



MLibby said:
How can I access an IFrame's id or name from within a child IFrame?

My application can have nested IFrames (one IFrame exists within another).
Each child IFrame needs to access its parent IFrame's javascipt methods.
However before it attempts to access the parent IFrame method it needs to
know if its parent is truley an IFrame and the correct IFrame.
I tried assigning each IFrame an ID and then having each IFrame check its
parent IFrame's ID however, I found that child IFrame can't retrieve thier
parent's IFrame ID. For example window.parent.id should return the name of
the IFrame's parent but for some reason the id is always null. The same is
true for an IFrame's name.
I also tried seing if the child's parent contains a method and then call
that method in hopes of retriving its IFrame ID, ie.
if (window.parent.somemethodl != null)
window.parent.somemethod();

function somemethod()
{

This works! However, when inside of the sommethod() call I still can't access the IFrame id or name.

Any ideas?

Mike

How can I retrieve an IFrame's parent id from within a nested child's IFrame?
 

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,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top