I have code to check if a window is closed. It works IF I stay on the same page.
With Internet Explorer, if I click on a link that then redirects to another site, that window.closed returns true even though the WINDOW never actually is closed.
I am doing this:
w = window.open("mypage.html");
var t = setInterval(function() {
if (!w) { alert('a'); }
if (w.closed) { alert('b'); }
if (!w || w.closed) {
clearInterval(t); hide('mainShadow');
}
}, 800);
Within "mypage.html", there is a link to another site. When going to that other side, the w.closed returns true
.
Is there a good way in IE to really check if the window is closed or not.
The contract isn't really satisfied because the window never actually closed.
This code works in Chrome, not in IE9
The contract isn't really satisfied because the window never actually closed.
This seems to be the origin of the confusion. The window
object in JavaScript-in-a-browser refers to window displaying a document as embodied in some browser window, but it does not refer to that window as the browser sees it itself. Nor is it the case that a single browser window is associated with a single window
instance. So a window
instance can be closed because it's not longer displayed. That's accurate because the window
element is not, strictly speaking, about the browser entity window
that is an external view of the window, as opposed the JavaScript object window
that is an internal view of the window that a document containing code sees.
The short version is that I don't believe there's a way to do this from within a web page, since the outer scope of visibility, the window
object, doesn't refer to the actual object you want to manipulate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With