javascript 如何在 iframe 中使用 window.open
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13587599/
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
how to use window.open in a iframe
提问by Sam
I have injected an iframe in a webpage. In the iframe I have added a window.open()
, like this:
我在网页中注入了一个 iframe。在 iframe 中,我添加了一个window.open()
,如下所示:
window.open("mypage.com", "_self");
But this refreshes the iframe with mypage.com. The requirement is to load this page in the same main browser.
但这会使用mypage.com刷新 iframe 。要求是在同一主浏览器中加载此页面。
How do I do that?
我怎么做?
回答by Quentin
Use window.open
if you want to open a window.
使用window.open
,如果你想打开一个窗口。
If you want to load a document into the current frame, then use location = "http://example.com";
如果要将文档加载到当前框架中,请使用 location = "http://example.com";
If you want to load a document into the top level frame, then use top.location = "http://example.com";
如果要将文档加载到顶级框架中,请使用 top.location = "http://example.com";
回答by huysentruitw
Try this:
试试这个:
window.top.location.href = "http://mypage.com";
回答by sroes
Change
改变
window.open("mypage.com", "_self");
To
到
window.open("mypage.com", "mypopupname");