Skip to content Skip to sidebar Skip to footer

Displaying A Confirm Dialog Box When The User Tries To Refresh/close/navigate To Another Web Page

I would like to warn the user with a confirm dialog box when he tries to refresh the page, navigate to another page, close the page. Just like Gmail does; for example when you writ

Solution 1:

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

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

  // For IE and Firefox prior to version 4
  if (e) {
    e.returnValue = 'Your text';
  }

  // For others
  return 'Your text';
};

Post a Comment for "Displaying A Confirm Dialog Box When The User Tries To Refresh/close/navigate To Another Web Page"