Search code examples
javascriptjqueryiframeparent

Access iframe's "unnamed" parent


If I had some thing like this:

<div id="parent">
<iframe....></iframe>
</div>

I could: window.parent.document.getElementById('parent').innerHTML. But I have something like this:

<div>
<iframe....></iframe>
</div>

Is there anyway of accessing this? I might have anywhere up to 20 iframes on a given page, and would prefer not to make 20 individual iframe pages.

Thanks, Jason


Solution

  • window.frameElement is a reference to the IFRAME element containing the current page. You can use window.frameElement.parentNode (inside of the IFRAME) to get the unnamed parent element.

    Be aware that the property is non-standard. frameElement seems to be supported in Firefox, Opera, and IE.