如果打开,则window.open()在IE11中返回null [英] window.open() returns null in IE11 if opening
问题描述
在具有默认设置的Windows 10上的IE中,如果我从本地计算机上的页面或本地网络上的服务器对外部Internet站点执行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或Windows 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!