5

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 run another block when window "win" is closed. What is the event and how do I run code on its detection?

AKWF
  • 12,126
  • 14
  • 88
  • 189

1 Answers1

3

You must use intervals to check when/if the window was close Here is how you'll 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 that helps.

Melanie
  • 1,168
  • 2
  • 16
  • 41
Neta Meta
  • 3,848
  • 9
  • 40
  • 66