-5

actually if session is going on and user directly close the browser close button then it shows some alert. and by seeing that alert he can continue or cancel the alert.

nik
  • 210
  • 3
  • 13
  • 1
    Googled 'alert when page closes', got http://stackoverflow.com/questions/333665/javascript-to-get-an-alert-when-closing-the-browser-window as a first result. Did you even try? – Tim Apr 21 '14 at 11:39
  • i tried same , which you answered but.. – nik Apr 21 '14 at 11:52

4 Answers4

3
window.onbeforeunload = confirmExit;
function confirmExit(){
    return confirm("Press a button!");
}
bobthedeveloper
  • 3,733
  • 2
  • 15
  • 31
thecodejack
  • 12,689
  • 10
  • 44
  • 59
1
window.onbeforeunload = function(){
  return 'Are you sure you want to leave?';
};
bobthedeveloper
  • 3,733
  • 2
  • 15
  • 31
0
window.onbeforeunload = function(){
    return confirm("Are you sure to leave? ");
}
Tuhin
  • 3,335
  • 2
  • 16
  • 27
0

This bellow script can be to detect the close event of browser and alert a messages using javascript. Works Perfectly On Mozilla firefox, Chrome and all famous browsers.

<script type="text/javascript">
window.onbeforeunload = function(){ myUnloadEvent(); }
function myUnloadEvent() {
    alert ('alert messages that you want to put');
}
</script>

Hope this will work perfectly.

gargAman
  • 111
  • 1
  • 5