Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a window exists in Javascript?

Tags:

javascript

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?

like image 962
Andrew Avatar asked Jan 24 '11 18:01

Andrew


People also ask

How do you check if a window is already open in JavaScript?

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.

How to check if popup window is closed in JavaScript?

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

Why is window opener null?

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.


1 Answers

if(window.opener && !window.opener.closed)
    alert('Yup, still there.');
like image 116
chaos Avatar answered Sep 24 '22 13:09

chaos