Click to See Complete Forum and Search --> : onUnload
domiflichi
01-29-2003, 04:22 PM
Is there another event handler or another way to perform some action when the browser is closed that does not get activated when a user hits 'back' or a link on the page? I need to perform a function that only gets executed when the browser is closed. Thanks, Jamie.
you can't get a function in javascript when a browser is closed, because javascript works on the client-side so you can only do something when the document goes unloaded --> onUnload=function().
domiflichi
01-29-2003, 04:49 PM
Thanks for the quick reply. Is there any way to prevent this OnUnload event handler from activating when the user hits the 'back' or a link on the page? Because I know it will activate if the browser is closed, but it also gets activated when hitting 'back' or a link, and the latter two are unacceptable in my situation. Thanks again.
Charles
01-29-2003, 08:34 PM
Oddly enough, the onunload handler is called whenever the document is unloaded. It doesn't matter how the document is unloaded. However, each link has an onclick handler that is called just before the link is activated. You can use this handler to overwrite the window's onunload handler. There's nothing that you can do about the back button.
window.onload = function () {for (j=0;j<document.links.length;j++) {document.links[j].onclick = function () {window.onunload = function () {}}}}