dossani dossani - 2 months ago 9
Javascript Question

FireFox doesn't display any warning dialog for window beforeunload event

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;


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;