在默认设置的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!