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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With