dossani dossani - 1 year ago 109
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;

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download