我有以下网页:
<html>
<head>
</head>
<body>
<h1>Wait until closed</h1>
<script>
function wait(popup){
if (!popup.closed){
setTimeout(wait,1000,popup);
} else {
alert('closed');
}
}
var popup = window.open("http://www.google.com", '', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes, width=1000 , height=800, top=' + screen.top + ', left=' + screen.left);
wait(popup);
</script>
</body>
</html>
当我用Chrome或Firefox打开它时,我会在关闭弹出窗口后看到消息“关闭”。然而,在IE11中,什么都不会发生。对这种行为差异的解释是什么?(也就是说,在这种情况下,IE11不遵守或不同地解释标准的哪一部分(如果有的话)?)
编辑:阅读了建议的答案,我尝试将setTimeout(wait,1000,popup)
更改为setTimeout(function() {wait(popup);},1000)
,如下所示:
<html>
<head>
</head>
<body>
<h1>Wait until closed</h1>
<script>
function wait(popup){
if (!popup.closed){
setTimeout( function() {
wait(popup);
}, 1000 );
} else {
alert('closed');
}
}
var popup = window.open("http://www.google.com", '', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes, width=1000 , height=800, top=' + screen.top + ', left=' + screen.left);
wait(popup);
</script>
</body>
</html>
但这也不起作用。
编辑:注释表明这是重复的,但由于尝试根据建议的答案更改代码直到现在才对我有效,所以我修改了问题,要求更改上面的代码,以便在IE11中工作(希望这是so规则允许的)。显示的代码不起作用。
发布于 2017-06-29 15:52:26
这个有点困扰我,所以我在一个本地文件上试了一下,得到了同样的行为。window.open在IE和边缘中都返回null。显然,如果启用了保护模式,window.open将在IE和Edge中返回null。
https://msdn.microsoft.com/en-us/library/Bb250462.aspx
我不知道怎么解决这个问题。也许是个合拍的画框?
https://stackoverflow.com/questions/44827653
复制相似问题