javascript onbeforeunload not showing custom message

JavascriptGoogle Chrome

Javascript Problem Overview


I have custom message to onbeforeunload event and was working well but I noticed today that it's not showing my message anymore. Instead it shows "changes you made may not be saved"

window.onbeforeunload = function () {

    return 'Custom message'
}

can anyone please let me know how to fix it?

Javascript Solutions


Solution 1 - Javascript

To avoid scamming, chromium and hence chrome have decided to remove the ability to set a custom message in the onbeforeunload dialog.

See this bug report from the 18th of February, 2016.

> onbeforeunload dialogs are used for two things on the Modern Web:

  1. Preventing users from inadvertently losing data.
  2. Scamming users.

>In an attempt to restrict their use for the latter while not stopping the former, we are going to not display the string provided by the webpage. Instead, we are going to use a generic string.

>Firefox already does this[...]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTushar aniView Question on Stackoverflow
Solution 1 - JavascriptKaiidoView Answer on Stackoverflow