Obtaining ID of container IFrame

Y

yashgt

My HTML is shown in an iframe. There is a link in the HTML that needs
the ID of the iframe to be used in the onclick event. How do I get it?
I tried accessing the target property, but it turns out to be
undefined. Also I do not know the frame number in the parent's frame
collection. SO I cannot do parent.frames[2].id.

Please help.
Yash
 
M

Martin Honnen

My HTML is shown in an iframe. There is a link in the HTML that needs
the ID of the iframe to be used in the onclick event. How do I get it?

By now there is wide support for
window.frameElement
so e.g.
if (window.frameElement) {
alert(window.frameElement.id);
}
will do in recent IE and Mozilla and Opera.
IE's documenation is here:
<http://msdn.microsoft.com/library/d...r/dhtml/reference/properties/frameelement.asp>
Supported there since IE 5.5.
I can't tell you the exact Mozilla and Opera versions from which on this
is supported.
You can always walk up to the parent window and parent.document and look
through the iframe elements.

And somehow your request sounds as if all you want is e.g.
<iframe name="frameName" src="whatever.html"></iframe>
and
<a href="whatelse.html" target="frameName">link</a>
but perhaps you really need script.
 

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

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top