通过位于iframe中的元素获取父iframe元素

时间:2016-09-02 10:53:00

标签: javascript html iframe

假设您有以下HTML:

<div>
    <iframe src="..">
       <!-- The following would be the content of the iframe -->
       <html><head></head><body>
           <span>I'm the node</span>
       </body></html>
    </iframe>
</div>

您有一个变量iframeNode,其中包含该iframe中的<span>元素。您的脚本上下文是父窗口。

您如何获得父iframe元素:

<iframe src="..."></iframe>

通过这个节点?

理论上:

var iframe = iframeNode.myParentIframeElementInTheParentScope;

1 个答案:

答案 0 :(得分:1)

如果DELETEiframespan的唯一引用是iframe,那么

iframeNode

将引用父窗口中的iframe元素。