Access iframe's “unnamed” parent

2019-08-05 09:42发布

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

3条回答
冷血范
2楼-- · 2019-08-05 10:25

so im assuming you control the the parents code

then you can iterate true all the iframes and give them a reference to the parent div to use.

查看更多
3楼-- · 2019-08-05 10:32

I think this will help you: document.getElementsByTagName("iframe").

W3School's Page

This method will return a vector with all elements with tag it found in the page.

查看更多
萌系小妹纸
4楼-- · 2019-08-05 10:33

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.

查看更多
登录 后发表回答