Last updated on May 17th, 2016 at 12:05 pm

Close Event In Javascript

For some versions of Firefox, IE (Internet Explorer) and Chrome browser here is the event that gets triggered when ever we close the browser window. This script will show you how to detect browser close event and alert messages using javascript. Moreover this script will be useful to call some ajax functions which terminate the connection from Database or something related when user close the browser.

<html>
<body>
<script type="text/javascript">
window.onbeforeunload = check;
function check()
{
return "Are you sure you want to exit this page?";
//or put whatever function you need to call when a user closes the web //browser.
}
</script>
</body>
</html>

Tested in latest version of Internet Explorer and Chrome. It is no longer working in latest version of Mozilla Firefox.

Leave a Reply

Your email address will not be published. Required fields are marked *