Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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