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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)