繁体   English   中英

如何使用iframe中的函数从父页面中删除iframe?

[英]How to remove iframe from parent page using a function inside the iframe?

我有一个使用bookmarklet放在页面上的iframe,当我导航到这个iframe中的某个页面时,我想让这个iframe关闭。

如何使用JavaScript?

注意:iframe和容器页面位于不同的域中。

据我所知,你不能从iframe的容器中删除DOM中的元素,除非它是相同的域,如果我由于跨域安全策略正确理解你。

如果这是可能的,你可以渗透银行网站和所有,这将是一个烂摊子。

除了@meder回答和他的评论如何使用iframe内的函数从父页面中删除iframe?

我发现这个答案关闭iframe跨域帮助我解决了我的问题。

更新 :我发现这个解决方案不适用于IE,我找不到解决方案:(

由于所谓的“同源政策”,这是不可能的( http://en.wikipedia.org/wiki/Same_origin_policy

如果它在同一个域内你可以尝试

jQuery('iframe-selector').remove(); // remove iframe
jQuery('iframe-selector').contents().empty(); // remove the iframe content
jQuery('iframe-selector').removeAttr('src'); // remove the source-attribute from the iframe
jQuery('iframe-selector').attr('src', 'javascript:return false;'); // remove the iframe source

您无法使用Iframe进行跨域脚本编写。

暂无
暂无

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

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