Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a javascript function of parent window when child is closed?

I am creating a pop-up window. After I am finished with the work on child (pop up) window and click close button, I need to call a JavaScript function of the parent window. How can I achieve this? I am not creating the child window myself but displaying the contents of some other URL.

like image 864
biluriuday Avatar asked Jan 23 '23 03:01

biluriuday


1 Answers

I don't think you can get an event, because you can't mess with the document itself when the URL is from a different domain. You can however poll and check the "closed" property of the window object:

var w = window.open("http://what.ever.com", "OtherWindow");
setTimeout(function() {
  if (w.closed) {
    // code that you want to run when window closes
  }
  else
    setTimeout(arguments.callee, 100);
}, 100);

You could also start an interval timer if you prefer:

var w = window.open("http://what.ever.com", "OtherWindow");
var interval = setInterval(function() {
  if (w.closed) {
    // do stuff
    cancelInterval(interval);
  }
}, 100);
like image 101
Pointy Avatar answered Jan 24 '23 16:01

Pointy