javascript - how to bind an close event to window.open() -
i have following function open url in window pop up:
function windowpopup(url, width, height) { // center var left = (screen.width / 2) - (width / 2), top = (screen.height / 2) - (height / 2); handle=window.open( url, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left ); }
i want able detect when window closed execute code. how can use handle in function bind unload or close?
i want know once window has been closed after shares twitter:
windowpopup("https://twitter.com/intent/tweet/?text=check%20out%20this%20website!&url=https%3a%2f%2fgoogle.com%2f", 500, 300);
update
i updated lar's suggestion:
function windowpopup(url, width, height) { // center var left = (screen.width / 2) - (width / 2), top = (screen.height / 2) - (height / 2); handle=window.open( url, "", "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left ); handle.onbeforeunload = function() { alert('bye!'); } }
while worked pop windows didn't work when closed twitter window...
you’re looking beforeunload
event:
handle.onbeforeunload = function() { console.log('bye!'); }
Comments
Post a Comment