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

时间:2022-08-23 10:15:48

I have an iframe I put on a page using a bookmarklet, I want this iframe to close itself when I navigate to a certain page inside this iframe.

我有一个iframe,我用bookmarklet放在页面上,我希望当我导航到iframe中的某个页面时,这个iframe能够自动关闭。

How to do that using JavaScript?

如何使用JavaScript?

Note: iframe and container page are in different domains.

注意:iframe和container page位于不同的域中。

4 个解决方案

#1


4  

As far as I know you cannot remove the element from the DOM from the iframe's container unless it's the same domain if I'm understanding you properly due to cross-domain security policies.

据我所知,您无法从iframe的容器中删除该元素,除非它是相同的域,如果我正确地理解您,因为跨域安全策略。

If this were possible you could infiltrate bank sites and all, it'd be a mess.

如果这是可能的,你可以渗透到银行网站和所有,这将是一团糟。

#2


3  

Beside @meder answer and his comments How to remove iframe from parent page using a function inside the iframe?,

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

i found this answer Close iframe cross domain Which helped me too much to solve my problem.

我发现这个答案很接近iframe cross domain,这对我解决问题帮助很大。

UPDATE: I found that this solution is not working on IE, and i failed to find a solution for that :(

更新:我发现这个解决方案对IE不起作用,我也没能找到解决方案:

#3


2  

it isn't possible due the so called 'same origin policy' ( http://en.wikipedia.org/wiki/Same_origin_policy )

这是不可能的,因为所谓的“同源策略”(http://en.wikipedia.org/wiki/Same_origin_policy)

if it's within the same domain you can try

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

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

#4


0  

You can't do cross-domain scripting with Iframes.

您不能使用iframe进行跨域脚本编写。

#1


4  

As far as I know you cannot remove the element from the DOM from the iframe's container unless it's the same domain if I'm understanding you properly due to cross-domain security policies.

据我所知,您无法从iframe的容器中删除该元素,除非它是相同的域,如果我正确地理解您,因为跨域安全策略。

If this were possible you could infiltrate bank sites and all, it'd be a mess.

如果这是可能的,你可以渗透到银行网站和所有,这将是一团糟。

#2


3  

Beside @meder answer and his comments How to remove iframe from parent page using a function inside the iframe?,

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

i found this answer Close iframe cross domain Which helped me too much to solve my problem.

我发现这个答案很接近iframe cross domain,这对我解决问题帮助很大。

UPDATE: I found that this solution is not working on IE, and i failed to find a solution for that :(

更新:我发现这个解决方案对IE不起作用,我也没能找到解决方案:

#3


2  

it isn't possible due the so called 'same origin policy' ( http://en.wikipedia.org/wiki/Same_origin_policy )

这是不可能的,因为所谓的“同源策略”(http://en.wikipedia.org/wiki/Same_origin_policy)

if it's within the same domain you can try

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

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

#4


0  

You can't do cross-domain scripting with Iframes.

您不能使用iframe进行跨域脚本编写。

相关文章