首页 文章

WIN 8.1上的IE11:具有相同名称的window.open正在打开新的弹出窗口

提问于
浏览
2

运行以下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>

如果您没有提到网址,则不会发生此行为 . (见下面的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和IE11中不会发生 . 我需要做些什么调整才能在IE11中使用它?

Update: 这似乎是IE的bug . 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: 仅当Internet Explorer以提升模式运行时才会发生这种情况 .

1 回答

  • 2

    请试试这..这将检查窗口是否仍然打开或关闭..

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

相关问题