0

I want to change the browser message on before window unload, following is the code am trying to work on

var displayMessage = true;
$(window).bind('beforeunload', function(){
    if(displayMessage){
        var message =  '-- You specify a custom message here ---'+'\n Thanks for visiting my site!';
        return message;
    }
});

With the above code the message i get on firefox is

This page is asking you to confirm that you want to leave - data you have entered may not be saved.

How to change this to custom message

Sarang
  • 754
  • 3
  • 9
  • 24
  • possible duplicate of [How can I override the OnBeforeUnload dialog and replace it with my own?](http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own) – Manwal Sep 12 '14 at 10:35
  • Some browsers show your message accompanied by their own, some don't. This is done to prevent scams or any other annoying behaviour. – MMM Sep 12 '14 at 10:41

1 Answers1

2

You will not be able to do so

From Mozilla.org "Note that in Firefox 4 and later the returned string is not displayed to the user. Instead, Firefox displays the string "This page is asking you to confirm that you want to leave - data you have entered may not be saved."

More info: https://developer.mozilla.org/en-US/docs/WindowEventHandlers.onbeforeunload

See Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=588292

Hamed Ali Khan
  • 1,108
  • 3
  • 23
  • 29