SC92
SC92

Reputation: 161

javascript internet explorer wont detect window.closed

I have this javascript code which runs when the browser detects if the user closes the popup windoow. It works in the browsers firefox, opera, chrome, but I get an error with internet explorer (the error is in dutch so i tried to translate). It does open a popup window, but it also opens a new tab in internet explorer, which is not the case with the other browsers.

This is the JS code. The error is giving on the line if newWindow.closed !== 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 code:

<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>

Upvotes: 0

Views: 246

Answers (1)

David R
David R

Reputation: 15639

It is a known IE bug, And you can find more information and workaround in the below given link.

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

Hope this helps!

Upvotes: 1

Related Questions