1

I want to display a popup with personal message when user close the browser I found many similar scripts but they work in firefox and not in chrome, Is there any solution to this ?

    window.onbeforeunload = function (event) {
    var message = 'Important: Please click on \'Save\' button to leave this page.';
    if (typeof event == 'undefined') {
        event = window.event;
    }
    if (event) {
        event.returnValue = message;
    }
    return message;
};

Also I am not having the message in the code but I have annother message like this : "Cette page demande de confirmer sa fermeture ; des données saisies pourraient ne pas être enregistrées"

user2285831
  • 419
  • 1
  • 5
  • 18
  • Please translate any messages to English; Stack Overflow is English-only, and without translation it is difficult to understand what you are talking about. – Heretic Monkey Oct 13 '16 at 21:37

1 Answers1

0

According to information at https://developers.google.com/web/updates/2016/04/chrome-51-deprecations?hl=en#remove_custom_messages_in_onbeforeload_dialogs

A window’s onbeforeunload property may be set to a function that returns a string that is shown to the user in a dialog box to confirm that the user wants to navigate away. This was intended to prevent users from losing data during navigation. Unfortunately, it is often used to scam users.

Starting in Chrome 51, a custom string will no longer be shown to the user. Chrome will still show a dialog to prevent users from losing data, but it's contents will be set by the browser instead of the web page.

With this change, Chrome will be consistent with Safari 9.1 and later, as well as Firefox 4 and later.

This means you can't get a custom message on the onbeforeunload event. If it is indeed to remind the user to save before exiting, the default browser message should basically say the same information (and will be based on the user's browser language) so you don't need to manually implement this feature.

Community
  • 1
  • 1
apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • Thanks apokryfos ! I didn't want to implement this feature for the user to remind him to save before exiting, but to remind him that there is some treatments that are loading and he should wait, so there are no default browser message for this case. – user2285831 Oct 13 '16 at 16:41