【问题标题】:javascript internet explorer wont detect window.closedjavascript Internet Explorer 不会检测到 window.close
【发布时间】:2018-04-01 06:58:00
【问题描述】:

我有这个 javascript 代码,当浏览器检测到用户是否关闭弹出窗口时运行。它可以在浏览器 firefox、opera、chrome 中运行,但我在 Internet Explorer 中遇到错误(错误是荷兰语,所以我尝试翻译)。它确实会打开一个弹出窗口,但它也会在 Internet Explorer 中打开一个新选项卡,这与其他浏览器不同。

这是 JS 代码。报错就行了if newWindow.closed !== false

无法关闭未定义引用的属性或检索 引用空值

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>

【问题讨论】:

    标签: javascript ajax internet-explorer-11


    【解决方案1】:

    这是一个已知的 IE 错误,您可以在下面给出的链接中找到更多信息和解决方法。

    https://support.microsoft.com/en-us/help/241109/bug-window-closed-property-returns-incorrect-values

    希望这会有所帮助!

    【讨论】:

    • 弹出窗口是供应商的外部网店,所以我无法控制它,也无法添加代码来查看弹出窗口是否关闭。这一切都需要在我身边完成
    猜你喜欢
    • 2013-02-21
    • 2019-11-20
    • 2021-12-24
    • 1970-01-01
    • 2015-06-24
    • 2012-12-10
    • 1970-01-01
    相关资源
    最近更新 更多