Friday, 17 February 2012

Detecting Browser close event in Javascript

This Script will show how to detect browser window (or) Tab Close Event and give some alert confirmation message using java Script or to call any server Side method. This will be useful to terminate Connection from Database Side or Something.

Works Perfectly on IE, Mozilla, Chrome and Safari.

<script language="javascript" type="text/javascript">

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

   function myUnloadEvent() {

       alert("Give some alert message");     

       //Or Call some Serverside Method



<body style="height:100%;">

//Some Body Content


1 comment:

  1. Hi.
    Your code was really helpful for me.
    Thank U vry much..!!!! :)