javascript WIN 8.1 上的 IE11:同名的 window.open 正在打开新的弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18373014/
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
IE11 on WIN 8.1 : window.open with the same name is opening new popup window
提问by Suresh
When running the below HTML page it is opening two popup windows. It is not the case with previous versions of IE. When window.open call is made with the same window name that has already opened, it should return the reference to the opened window. But in IE11 it is opening another new window.
运行下面的 HTML 页面时,它会打开两个弹出窗口。以前版本的 IE 并非如此。当 window.open 调用与已经打开的窗口名称相同时,它应该返回对打开窗口的引用。但在 IE11 中,它打开了另一个新窗口。
<html>
<head>
<script type="text/javascript">
window.open("http://www.google.com", "test", "resizable=no,scrollbars=yes,width=260,height=225");
window.open("http://www.google.com", "test", "resizable=no,scrollbars=yes,width=260,height=225");
</script>
</head>
</html>
This behavior is not happening, if you not mentioned a url. (See below html page). Below html page is launching only one popup window.
如果您没有提到网址,则不会发生这种行为。(见下面的html页面)。下面的 html 页面仅启动一个弹出窗口。
<html>
<head>
<script type="text/javascript">
window.open("", "test", "resizable=no,scrollbars=yes,width=260,height=225");
window.open("", "test", "resizable=no,scrollbars=yes,width=260,height=225");
</script>
</head>
</html>
When we provide url or navigate to url window is losing its name. If you try to get the popup window name using window.name it is returning empty string.
当我们提供 url 或导航到 url 窗口时,它的名称正在丢失。如果您尝试使用 window.name 获取弹出窗口名称,它将返回空字符串。
It is happening only in Windows 8.1 and IE 11 and not happening in Windows 7 and IE11. Are there any tweaks I need to do to make this work in IE11?
它只发生在 Windows 8.1 和 IE 11 中,而不发生在 Windows 7 和 IE11 中。我需要做任何调整才能在 IE11 中工作吗?
Update:It seems to be IE bug. IE team is investigating it. https://connect.microsoft.com/IE/feedback/details/797964/ie11-win-8-1-window-open-with-the-same-name-is-opening-new-popup-window#details
更新:这似乎是 IE 错误。IE 团队正在调查它。 https://connect.microsoft.com/IE/feedback/details/797964/ie11-win-8-1-window-open-with-the-same-name-is-opening-new-popup-window#details
Update 2:It is happening only if Internet Explorer runs in elevated mode.
更新 2:仅当 Internet Explorer 在提升模式下运行时才会发生。
回答by BonieZat
Please try this.. this will check the window is still open or closed..
请试试这个..这将检查窗口是否仍然打开或关闭..
<script type="text/javascript">
var myWindow = null;
if(!myWindow || (myWindow && myWindow.closed)){
myWindow = window.open("http://www.google.com", "test", "resizable=no,scrollbars=yes,width=260,height=225");
}
else{
myWindow.location.href = 'http://www.google.com';
}
</script>