Code
<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