0

Currently working the latest version of Firefox desktop browser. Trying to capture the window beforeunload event. Below code works for IE, Chrome and Safari but not with Firefox.

window.addEventListener("beforeunload", function(e) {
  var confirmationMessage = "Test Test";
  e.returnValue = confirmationMessage;
  return confirmationMessage;
});
dossani
  • 1,892
  • 3
  • 14
  • 23
  • Possible duplicate of [Is it possible to display a custom message in the beforeunload popup?](http://stackoverflow.com/questions/38879742/is-it-possible-to-display-a-custom-message-in-the-beforeunload-popup) – Dekel Aug 24 '16 at 18:01

1 Answers1

0

From Firefox's documentation:

To combat unwanted pop-ups, browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with.

You cannot show pop-up if user didn't interacted with the page before. Also, it is better to use the following code:

window.onbeforeunload = function(e){
  var dialogText = 'Dialog text here';
  e.returnValue = dialogText;
  return dialogText;
};