WIN 8.1上的IE11:window.open正在打开新的弹出窗口

IE11 on WIN 8.1 : window.open with the same name is opening new popup window

本文关键字:窗口 上的 IE11 open window WIN      更新时间:2023-09-26

运行下面的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>

如果你没有提到url,这种行为就不会发生。(请参阅下面的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>

当我们提供url或导航到url时,窗口将丢失其名称。如果您尝试使用window.name获取弹出窗口名称,则返回空字符串。

它只在Windows 8.1和IE 11中发生,而在Windows 7和IE 11中没有发生。我需要做什么调整才能在IE11中工作吗?

更新:这似乎是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

更新2:只有当Internet Explorer在提升模式下运行时,才会发生这种情况。

请尝试此操作。。这将检查窗口是否仍然打开或关闭。。

<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>