Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check that a window has been closed in JavaScript?

For example, I have JavaScript like this:

windowHandle = window.open('http://www.irt.org/','testWindow','height=200,width=200');

I would like to check whether the 'testWindow' is closed and run a function if it is.

I have Googled this problem but so far all I found is:

if (testWindow.close) {..}

which is only run once. So I am wondering if there is an event triggered when a window is closed?

like image 355
user1871516 Avatar asked Nov 13 '22 05:11

user1871516


1 Answers

I would use a lightbox rather than a window.open for a task such as this. Most of the time it would be better to keep the user embedded into your site especially if you're doing something like an upload.

I've used colorbox to do similar tasks in the past. Here's a link http://www.jacklmoore.com/colorbox/

Then you would just attach a callback to the closed event of the colorbox

like image 144
Matt Bucci Avatar answered Nov 15 '22 00:11

Matt Bucci