Call Some Javascript When The User Closes A (popup) Window
Solution 1:
The following code works in Firefox, IE 8, and "Google Chrome".
In the the opening window
<scriptsrc="http://ajax.googleapis.com/ajax/libs/mootools/1.2.3/mootools-yui-compressed.js"></script><script>functionon_popup_close(){
//put your code herealert('it closed');
}
</script>
In the popup
<script>functioninform_parent(){
opener.on_popup_close();
}
window.onbeforeunload = inform_parent;
</script>
The first line in the code for the opening window can be your favorite framework that implements the dollar sign operator.
Solution 2:
you can check from the parent window if the child window still exists (e.g. check every 100 ms or so) and launch script if not...
Solution 3:
Have a look at the window.opener
property. Except for IE it has pretty good support. You could use it to call some javascript functions in your parent window before window.close()
ing your popup.
Solution 4:
No idea whether it works in practice, but if the issue is navigating to internal pages, why not set a global variable of some type whenever a link is clicked in page, and check for that onunload?
Something like (excuse the jQuery, I'm extremely lazy):
INTERNAL_CLICKED = false;
$("a").click(function() {
INTERNAL_CLICKED = true;
});
window.onunload = function() {
if(!INTERNAL_CLICKED) {
// perform window unload code
}
}
To reiterate, completely untested, but who knows - it may well just work for you. Although, I would beware, that's probably going to fire on refresh as well.
Solution 5:
Hi You can use following function on onbeforeunload
event fired by window
just before the window.close
window.onbeforeunload = function () {
// stuff do do before the window is unloaded here.
}
let me know if it not solve ur probelm
Post a Comment for "Call Some Javascript When The User Closes A (popup) Window"