Can I detect when the browser is about to close down (not just the window) and have code that does something before shutting down?

Jayesh Nazre

The best you can do is watch for the unload even.

NOTE: This piece of code is executed even if u refresh the page.Because when u refresh the page , the browser paints a new screen so the unload event gets fired.

This event gets fired in IE as well as NS6 (Mozilla), in NS4+ it does not work. However in NS4+ when u refresh the page it gets fired, but when you close the browser it does not.

<html>
<head>
<script language=javascript>
function cleanUp() {
	alert ("I AM CLOSING");
}
</script>
</head>
<body onunload=cleanUp()>
</body>
</html>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact