Search code examples
javascriptonbeforeunload

Leave Page Stay On Page With Custom Message


I am trying to put some custom text on the popup that asks for leave page or stay on the page. I tried this

window.onbeforeunload = function () {
             return "This is my custom message";
         };

But Mozilla and Chrome still says their own messages while IE shows my message. So what I am trying to do is it should show my custom message with Leave and Stay buttons. And I am sure I have seen in some webiste although I don't remember which website :(

Is it possible?


Solution

  • Firefox 4 and higher will not show your custom message. See also this answer:

    From MDN:

    Note that in Firefox 4 and later the returned string is not displayed to the user. See Bug 588292.

    This "Bug" is actually a (imho questionable) feature.. so there's no way to display the message in Firefox 4. If you think it should be changed, comment on that bug so the Firefox developers will know that people actually want to be able to show a custom string.