简体   繁体   English

如何从内容访问自己的iframe

[英]How to access its own iframe from contents

I have an iframe list like that: 我有一个这样的iframe列表:

<iframe src="foo">
    <button class="dissmiss">Close</button>
    <script>
        // Do job here...
    </script>
</iframe>
<iframe src="bar">
    <button class="dissmiss">Close</button>
    <script>
        // Do job here...
    </script>
</iframe>
.
.
.
<iframe src="baz">
    <button class="dissmiss">Close</button>
    <script>
        // Do job here...
    </script>
</iframe>

How can I get the iframe with js or jquery? 如何使用js或jquery获取iframe? I want to remove the iframe when the button is clicked: 我想在单击按钮时删除iframe:

parentIframe.remove();

PS: They have same domain. PS:它们具有相同的域。

From any iframe window (if not cross-domain) you can refer to the iframe HTMLElement on the parent page with 在任何iframe窗口 (如果不是跨网域)中,您都可以使用以下内容引用父页面上的iframe HTMLElement

window.frameElement

When using this, you don't need to know id or class of the iframe , or count iframe tags within a parent document. 使用此功能时,您无需知道iframe idclass ,也无需计数父文档中的iframe标签。

If you want to access the content of an Iframe: Try to assign some unique id to the iframe . 如果你想访问一个iframe的内容:尝试一些独特的ID分配给iframe

Try this, hope it will work 试试这个,希望它能起作用

 parent.$('body').find('Iframe').html();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM