我有这个 JavaScript 代码,当浏览器检测到用户是否关闭弹出窗口时运行。它可以在 firefox、opera、chrome 浏览器中运行,但我在 Internet Explorer 中遇到错误(错误是荷兰语,所以我尝试翻译)。它确实会打开一个弹出窗口,但也会在 Internet Explorer 中打开一个新选项卡,而其他浏览器则不会出现这种情况。
这是JS代码。错误出现在 if newWindow.close !== false
Can not close the property of an undefined reference or retrieve a reference to an empty value
function hyperLink(link) {
var newWindow = window.open(link.href, "Hyperlink", "status=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=" + screen.width / 1.5 + ",height=" + screen.height / 1.5 + "");
var interval = window.setInterval(function () {
if (newWindow.closed !== false) // for opera
{
$.ajax({
url: "index.php?route=extension/module/filter_product/getSupplierName",
type: "POST",
data: {supplier_name : link.name},
success: function(result) {
// your success handler
/*console.log("success");
console.log(result);*/
}
});
window.clearInterval(interval);
}
}, 500);
}
HTML 代码:
<div class="col-md-3 text-center hyperlink-image">
<a href="<?php echo $supplier['href']; ?>" onclick="hyperLink(this)" target="Hyperlink" name="<?php echo $supplier['name']; ?>">
<img src="<?php echo $supplier['thumb']; ?>" alt="<?php echo $supplier['name']; ?>"/>
</a>
</div>
最佳答案
这是一个已知的 IE 错误,您可以在下面给出的链接中找到更多信息和解决方法。
https://support.microsoft.com/en-us/help/241109/bug-window-closed-property-returns-incorrect-values
希望这有帮助!
关于javascript Internet Explorer 不会检测 window.close,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46843426/