javascript Internet Explorer 不会检测 window.close

标签 javascript ajax internet-explorer-11

我有这个 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/

相关文章:

html - 奇怪的 "line"出现在 GridView 中——是 CSS 还是边框还是什么?

javascript - IE 11 v11 不尊重单机输入上的 "disabled"属性

testing - 我无法启动 Internet Explorer 11,总是在 Windows 10 中打开 Edge

javascript - 使用 PHP 和 Json 的动态 dhtmlx 组织结构图

javascript - 我想将值更新为 json 对象,其中 Javascript 中已存在键

javascript - 在 Phonegap 中读取本地文件

php - 如何保护ajaxRequest.open php脚本

javascript - node.js 事件循环是否像 ajax 调用?

asp.net - 我可以避免 UpdatePanel 杀死 View 状态吗?

javascript - Vanilla JS 查找缺少子元素的元素