Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript to check when the browser window is closed

Tags:

javascript

Does anyone know any way that I can use javascript to check when the browser window is closed and pop-up a confirmation dialog to ask whether the user is confirm to exit the browser or change his mind to stay?

like image 350
Jin Yong Avatar asked Apr 30 '09 05:04

Jin Yong


1 Answers

window.onbeforeunload = function (e) {
  var e = e || window.event;

  //IE & Firefox
  if (e) {
    e.returnValue = 'Are you sure?';
  }

  // For Safari
  return 'Are you sure?';
};

https://developer.mozilla.org/en/DOM/window.onbeforeunload

like image 109
Chad Grant Avatar answered Oct 10 '22 04:10

Chad Grant