How to detect browser closing and navigating to some other page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
<script type="text/jscript">
var leaving=true;
window.onbeforeunload = function(e)
{
      if (!e) e = event;
      if (leaving) e.returnValue = "You might loose your changes";
}

</script>
  <title></title>
  </head>
  <body>
  <a href="http://www.google.com/">Leave</a>
<a href="page1.htm" onClick="leaving=false">stay on site</a>

  </body>
</html>

1 comment: