How can I detect closing an external window in JS?

I have a piece of code that opens a window with

$("#authorization_link").click(function() { win = window.open($(this).attr("href"),'width=800,height=600'); }); 

Now I want to start another block when the "win" window is closed. What is an event and how to run the code when it is detected?

+4
source share
1 answer

You should use the intervals to check when / if the window was closed. Here's how you do it:

 win = window.open($(this).attr("href"),'width=800,height=600'); function checkIfWinClosed(intervalID){ if(win.closed){ alert('windowsClosed'); clearInterval(intervalID); } } var interval = setInterval(function(){ checkIfWinClosed(interval); },1000); 

And here is a working example in fiddle

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1485672/


All Articles