Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to detect browser close when browser [X] is clicked ?

0.00/5 (No votes)
7 Mar 2011 5  
Code...

Code


XML
<html>
<head><title>Detect Browser Exit</title>
<script type="text/javascript" language="Javascript">

function DetectBrowserExit()
{
   alert('Execute task which do you want before exit');
}

window.onbeforeunload = function(){ DetectBrowserExit(); }

</script>
</head>
<body>
Detect Browser Exit
</body>
</html>


jQuery


I found the code in jQuery. Clickety[^]

Browser Compatibility


I have tested this script in the following Web browsers:


  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Safari

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here