关闭iframe并刷新父跨域 [英] Close iframe and refresh parent cross domain
问题描述
我有一个加载在别人页面上的iframe。当iframe关闭时,我想刷新父页面。
我目前使用类似于此处所述的哈希hack:关闭iframe跨域
虽然这种方法在IE9中存在安全问题,但如此我仍然在寻找更好的解决方案或IE解决方案。
有什么想法?
$ b 相关:< a href =https://stackoverflow.com/questions/3871363/iframe-on-unload-refresh-parent-page/> IFrame on unload刷新父页面
如果你的网页在里面:
var parent = window.parent;
if(parent&& parent.postMessage){
parent.postMessage(closed);
}
在其他人页面上:
window.onmessage = function(event){
if(event.data ===closed){
location.reload();
}
};
I have an iframe that loads on someone else's page. When the iframe is closed I would like to refresh the parent page.
I currently employ a hash hack similar to what's described here: Close iframe cross domain
This method gives security problems in IE9 though, so I'm still looking for better solutions or an IE workaround..
Any ideas?
Related: IFrame on unload refresh parent page
I think the only reliable way is to use postMessage in modern browsers for cross-domain communication, have not tested it but check this code part out... of course this only works if the "someone else's page" is somehow changeable
so inside if your page you do:
var parent = window.parent;
if (parent && parent.postMessage) {
parent.postMessage("closed");
}
on the other persons page:
window.onmessage = function(event) {
if (event.data === "closed") {
location.reload();
}
};
这篇关于关闭iframe并刷新父跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!