-1
window.addEventListener("beforeunload", function (e) {
    window.event.returnValue = "真的要刷新页面么?";
    return '2222';
});

How to self-customized the prompt box warning words when closing or updating an unsaved page in Chrome , and listen the confirm or cancal button click event ?

1 Answers1

0

The beforeunload dialog bog isn't customizable. Any value other than the empty string indicates a request to confirm unloading the document, but the value itself isn't used for anything.

You can use e.preventDefault() instead if you like.

Reference: § 7.8.11.1 The BeforeUnloadEvent interface

This changed in Chrome 51, Firefox 44, and Safari 9.1 (see 2).

Josh Lee
  • 171,072
  • 38
  • 269
  • 275