Skip to content

Instantly share code, notes, and snippets.

@weizman
Last active January 30, 2019 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weizman/76832789d5fe0cb7aeac4238a7064508 to your computer and use it in GitHub Desktop.
Save weizman/76832789d5fe0cb7aeac4238a7064508 to your computer and use it in GitHub Desktop.
cancelable `beforeunload` event example
// by https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload#Example
window.addEventListener("beforeunload", function (event) {
event.preventDefault(); // Cancel the event as stated by the standard.
event.returnValue = ''; // Chrome requires returnValue to be set.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment