1

I have a JS that opens a new tab. And I want to refresh the original window but only once the opened tab is closed. How would you do it?

Here's the code I have now (which obviously doesn't work - it does the refresh immediately after opening the new window):

window.open( SOME_WINDOW );
window.location.reload();
Avi Meir
  • 980
  • 3
  • 11
  • 26

1 Answers1

3

You can do it with something like this. Store the window handle, and use a polling timer to check the closed property of the window.

var childwindow = window.open(SOME_WINDOW); 
var timer = setInterval(function() {   
  if(childwindow.closed) {  
    clearInterval(timer);  
    window.location.reload();
  }  
}, 1000); 

Another solution (even nicer) can be found here

Community
  • 1
  • 1
bart s
  • 5,068
  • 1
  • 34
  • 55
  • Perfect. Thanks! I actually prefer your solution more, as I don't want the child to perform actions on parent. Makes child more modular IMO. – Avi Meir Dec 12 '12 at 10:55