Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.closed is always true

I'm opening a child window to another site where I don't control the content. I've implemented the pattern I found here of using a set timeout to check the window.closed property.

I've found this confirmed bug report for edge. Edge Issue Report

Here is the code as it sits now.

var myWindow = window.open(
      url,
      'myWindow',
      'height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes');  

// Check for the myWindow to close. When closed attempt to validate.
var timer = setInterval(checkWindow, 1000);

function checkWindow() {
debugger;
    // Try Block to catch our popup window being blocked
    try {           
        if(myWindow.closed) {
            clearInterval(timer);
            //do stuff here
        }
    }
    catch(e) {

        clearInterval(timer);
        //handle blocked popups and other stuff         
    }
}

when it hits the debugger step and I check myWindow.closed it is always true. In chrome it is false until I actually close the child window. Is there a work around or different pattern people are using?

like image 355
Robert Young Avatar asked Nov 15 '25 14:11

Robert Young


1 Answers

Take into account, that window.closed always returns true, if the newly opened URL isn't from the same origin / domain as it is opened from:

If the newly opened browsing context does not share the same origin, the opening script will not be able to interact (reading or writing) with the browsing context's content.

like image 191
BenJ1337 Avatar answered Nov 18 '25 20:11

BenJ1337



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!