Last active
March 19, 2021 08:45
-
-
Save cheeyeo/518b402d7198d50a120a to your computer and use it in GitHub Desktop.
tracking when window.open closes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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>"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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