// JavaScript event for when the user closes the window.
window.onbeforeunload = () => {
return "Do you really want to close?";
};
var win = window.open("http://www.google.com");
var winClosed = setInterval(function () {
if (win.closed) {
clearInterval(winClosed);
foo(); //Call your function here
}
}, 250);