I've seen ways of seeing if a window a particular script opened is still opened, but what if it didn't?
I have a small window that has a button to click to load the large window. When I close the large one, I want a particular onUnload
or onBeforeUnload
to fire iff the small one is closed; if it's still open, those procedures will not fire. I may be having simply a massive brain fart but I can't figure out how to check if the other window is open. The big one isn't opening it, so I can't simply record the handle from opening it.
In shorter terms: If window A opened window B, how can I check within window B if window A still exists?
How to check if an opened browser window is closed or not in JavaScript? To check if an opened browser window is closed, you can use the closed property in referenced window object in JavaScript. The property returns a boolean true if the window is closed and false if the window is in the opened state.
Here is the code: var win = window. open('http://www.google.com', 'google','width=800,height=600,status=0,toolbar=0'); var timer = setInterval(function() { if(win. closed) { clearInterval(timer); alert('closed'); } }, 1000);
If this window was not opened by being linked to or created by another, returns null . If the opener is not on the same origin as the current page, functionality of the opener object is limited. For example, variables and functions on the window object are not accessible.
if(window.opener && !window.opener.closed)
alert('Yup, still there.');
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