How to set up the message "Changes you have made may not be saved." for windows.onbeforeunload?

I am testing on Google Chrome.

I did a search and found that someone was using:

window.onbeforeunload = function() { if (hook) { return "Did you save your stuff?" } } 

But when I use it, I still get "The changes you made may not be saved." message. How can I change it to what I want?

+6
source share
1 answer

You cannot, the ability to do this has been removed in Chrome 51. This is widely considered a security issue, and most vendors have removed support.

Custom messages in the onbeforeunload dialog box (deleted) :

A function that returns a string can be set to the onbeforeunload property for windows. If the function returns a string, a dialog box is displayed before the page is unloaded, confirming that the user really wants to leave. The string provided by the function will no longer be displayed in the dialog box. A general line that is not under the control of the web page will be displayed.

Comments

It comes with Safari 9.1 and comes with Firefox with Firefox 4. Safari considers this a security patch and assigns it CVE-2009-2197 (see https://support.apple.com/en-us/HT206171 ). Approved with the intention of https://groups.google.com/a/chromium.org/d/msg/blink-dev/YIH8CoYVGSg/Di7TsljXDQAJ .

Specification

Established standard

Status in chromonics

Deleted ( startup error ):

  • Chrome for desktop 51
  • Chrome for Android version 51
  • Android WebView release 51
  • Opera release 38
  • Opera for Android version 38
+12
source

Source: https://habr.com/ru/post/1012271/


All Articles