Re: Accessing Nested IFrame's Parent ID and Names

M

Marina

What is the code in 'somemethod'? Which IFrame's id or name can you not
access?

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.
 
S

Steven Cheng[MSFT]

Hi Mike,

As for the get Parent Iframe id from the nested Iframe page, here are some
of my suggestions:

1. The window.parent.id won't work for this because the window.id represent
the id of the whole window object of the parent page rather than the id of
the iframe in the parent page. Do you think so?

2. I'm not sure whether there are more than one iframes in your page? if
only one iframe ,I think we can use the document.getElementByTagName script
function to get the <iframe> element reference in the parent page, for
example, the following function will get the first <iframe> tag in the
parent page and display its "id" attribute.

function showparentinfo()
{
elm = window.parent.document.getElementsByTagName("iframe")[0];
alert(elm.id);
}

Please have a try to see whether it helps. Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top