window.open() 如果打开,则在 IE11 中返回 null

window.open() returns null in IE11 if opening(window.open() 如果打开,则在 IE11 中返回 null)
本文介绍了window.open() 如果打开,则在 IE11 中返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在默认设置的 Windows 10 上的 IE 中,如果我从本地计算机上的页面或本地网络上的服务器对外部互联网站点执行 window.open(),我会得到null.

In IE on Windows 10 with default settings, if I perform a window.open() against an external internet site from a page on my local machine or a server on my local network, I get null.

请看下面我的复制品.在 Windows 7 或 Google Chrome 上的 IE 中不会发生这种情况.

See my repro below. This doesn't happen in IE on Windows 7 or Google Chrome.

有趣的是,如果我为 Intranet 区域打开启用保护模式"(这样 Intranet 区域和 Internet 区域中的保护模式相同),那么问题就消失了.但是,我需要它在不要求用户这样做的情况下工作.

Interestingly, if I turn on "Enable Protected Mode" for the Intranet Zone (so that Protected Mode are the same in the Intranet Zone and Internet Zone), then the problem goes away. However, I need this to work without requiring users to do this.

我没有找到任何明确的 Microsoft 文档来解释这种行为.我在 EdgeHTML 问题上提出了 一个问题网站,但想看看 SO 上的社区是否对为什么会发生这种情况有任何见解.

I haven't found any clear Microsoft documentation that explains this behavior. I raised an issue on this on the EdgeHTML issues site, but wanted to see if the community on SO has any insight into why this is happening.

谢谢!

<!DOCTYPE HTML>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script>
        var popupWindow = null;

        function openWindow() {
            popupWindow = window.open('http://microsoft.com', '_blank', 'left=100;top=100;height=100;width=100');
        }

        function checkWindowStatus() {
            if (popupWindow) {
                document.getElementById('status').innerHTML += '- Truthy reference. Closed? ' + popupWindow.closed + '</br>';
            } else {
                document.getElementById('status').innerHTML += '- Falsy reference: ' + popupWindow + '</br>';
            }
        }
    </script>
</head>

<body>
    <h2>Popup Issue</h2>
    <button onclick="openWindow()">Open Window</button>
    <button onclick="checkWindowStatus()">Check Window Status</button>
    <button onclick="popupWindow.close()">Close Window</button>
    <p id="status"></p>
</body>

</html>

推荐答案

好像保护模式不允许在当前域之外打开新窗口,所以你可以尝试用空白页和之后打开窗口更新位置.

It seems that protected mode doesn't allow to open new window outside of the current domain, so you can try to open the window with a blank page and after update the location.

<script>
    var popupWindow = null;

    function openWindow() {
        popupWindow = window.open('', '_blank', 'left=100;top=100;height=100;width=100');
        popupWindow.location = 'http://microsoft.com';
    }

    function checkWindowStatus() {
        if (popupWindow) {
            document.getElementById('status').innerHTML += '- Truthy reference. Closed? ' + popupWindow.closed + '</br>';
        } else {
            document.getElementById('status').innerHTML += '- Falsy reference: ' + popupWindow + '</br>';
        }
    }
</script>

这篇关于window.open() 如果打开,则在 IE11 中返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)