Access iframe's “unnamed” parent

左心房为你撑大大i 提交于 2019-12-11 10:03:57

问题


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


回答1:


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.




回答2:


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:


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.



来源:https://stackoverflow.com/questions/6066271/access-iframes-unnamed-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!