Javascript 从 iframe 关闭父弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13568999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Closing parent popup window from iframe
提问by Mike_G
On domain1.com I have a link that opens a popup to domain2.com. Within the popup is an iframe, also hosted on domain2.com. From within the iframe, i am trying to close the popup window. I seem to be getting confused on how to do this. From the iframe, do I call a javascript function defined in the popup that will close the window? Can I close the window directly from the iframe?
在 domain1.com 上,我有一个链接可以打开 domain2.com 的弹出窗口。弹出窗口中有一个 iframe,也托管在 domain2.com 上。在 iframe 中,我试图关闭弹出窗口。我似乎对如何做到这一点感到困惑。从 iframe 中,我是否调用在弹出窗口中定义的 javascript 函数来关闭窗口?我可以直接从 iframe 关闭窗口吗?
回答by 03Usr
Using this: parent.window.close();or this: top.window.close();you should be able to close it.
使用 this:parent.window.close();或 this:top.window.close();你应该能够关闭它。

