Search code examples
messageonbeforeunload

how to modify the message using onbeforeunload in chrome


I want to use my message like "Are you sure?" when closing the browser.But, the following code do not means.Chrome still given the default tips.

window.onbeforeunload = function(){
        console.log("test");
        return 'the message I want to use';
}

the version of chrome:51.0.2704.106 m. Wish the answers, thanks.


Solution

  • from Chrome 51, Custom messages in onbeforeunload dialogs was remove, instead, a generic string not under the control of the webpage will be shown.

    Read the following link for more detail:

    Custom messages in onbeforeunload dialogs (removed)