Is it possible to display a custom message in the pre-uninstall popup?
P粉478445671
P粉478445671 2023-08-24 09:27:52
0
2
517
<p>When using <code>window.onbeforeunload</code> (or <code>$(window).on("beforeunload")</code>), is it possible to display the self in the pop-up window? Define message? < /p> <p>Maybe a little trick for the major browsers? </p> <p>Looking at the existing answers, I think in the past using something like <code>confirm</code> or <code>alert</code> or <code>event.returnValue</code> Things were possible, but now it seems they no longer work. </p> <p>So, how to display custom message in beforeunload popup? Is this even/still possible? </p>
P粉478445671
P粉478445671

reply all(2)
P粉186904731

Not anymore. All major browsers started ignoring the actual message and only showing their own.

correct. A long time ago you could use confirm or alert, more recently you could return a string handler from onbeforeunload and the string would be shown. The contents of the string are now ignored and treated as flags.

When using jQuery's on you do have to use returnValue on the original event:

$(window).on("beforeunload", function(e) {
    // Your message won't get displayed by modern browsers; the browser's built-in
    // one will be instead. But for older browsers, best to include an actual
    // message instead of just "x" or similar.
    return e.originalEvent.returnValue = "Your message here";
});

Or the old fashioned way:

window.onbeforeunload = function() {
    return "Your message here"; // Probably won't be shown, see note above
};

That's all you can do.

P粉143640496

tl;dr - You can no longer set a custom message in most modern browsers

In order to set a confirmation message before the user closes the window, you can use

jQuery

$(window).bind("beforeunload",function(event) {
    return "You have some unsaved changes";
});

Javascript

window.onbeforeunload = function() {
    return "Leaving this page will reset the wizard";
};

    It is important to note that you cannot place confirmation/alert internal beforeunload


Here are the results using a browser I have access to:

Chrome:

Firefox browser:

Safari:

IE:

For more information on browser support and removal of custom messages:

  1. Chrome Removed Support for custom messages
  2. in version 51
  3. Opera Removed in version 38 Support for custom messages
  4. Firefox removed support for custom messages in version 44.0 (still looking for source of this information)
  5. Safari Removed in version 9.1 Support for custom messages
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template