Monday, December 31, 2012

How to ask user if want to leave current page in JavaScript?


Add function into onbeforeunload
var unsavedChanges = false;
window.onbeforeunload = function() {
  if (unsavedChanges) return 'You have unsaved changes!';
}

https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload