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?

RubyRedGrapefruit
  • 12,066
  • 16
  • 92
  • 193

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,198
  • 2
  • 17
  • 42
Neta Meta
  • 4,001
  • 9
  • 42
  • 67