Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Last active March 19, 2021 08:45
Show Gist options
  • Save cheeyeo/518b402d7198d50a120a to your computer and use it in GitHub Desktop.
Save cheeyeo/518b402d7198d50a120a to your computer and use it in GitHub Desktop.
tracking when window.open closes
// http://stackoverflow.com/questions/3291712/is-it-possible-to-open-a-popup-with-javascript-and-then-detect-when-the-user-clo
// The window.opener property refers to the page that spawned this popup.
// For example, if I wrote a function named callingPageFunction on my original page, I would call it from the popup like this:
$(window).unload(function() {
window.opener.callingPageFunction()
});
var wnd = window.open("file.html", "youruniqueid", "width=400, height=300");
wnd.onunload = function(){
// do something
wnd.opener.dosomething();
};
//monitor the closing of a popup window
var win = window.open("http://dev.com/index.php?m=social&a=testLinkedIn",'','height=500,width=500');
var winTimer = window.setInterval(function()
{
if (win.closed !== false)
{
// !== is required for compatibility with Opera
window.clearInterval(winTimer);
log('win closed...');
}
}, 200);
// using window.opener to access parent window object
// http://wisercoder.com/javascript-jquery-parent-windows/
// Open a new window
var myWindow = window.open("", "myWindow", "width=200, height=100");
// Write some text in the new window
myWindow.document.write("<p>This is 'myWindow'</p>");
// Write some text in the window that created the new window
myWindow.opener.document.write("<p>This is the source window!</p>");
// we want to trigger an event in parent window when child window succeeds
var child = window.open("", "myWindow", "width=200, height=100");
child.opener.trigger('some_event')
// in parent window
$(window).on('some_event', function(){console.log('success!');});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment