Is it possible to display a custom message in the pre-uninstall popup?
P粉478445671
2023-08-24 09:27:52
<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>
Not anymore. All major browsers started ignoring the actual message and only showing their own.
correct. A long time ago you could use
confirm
oralert
, more recently you could return a string handler fromonbeforeunload
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 usereturnValue
on the original event:Or the old fashioned way:
That's all you can do.
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
Javascript
It is important to note that you cannot place
confirmation/alert
internalbeforeunload
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: