Created
January 9, 2019 17:37
-
-
Save snaveevans/141e8576f45539efdeb0b50f2c31cedd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("beforeunload", function(e) { | |
// check to cancel | |
console.log("checking if we should display confirmation dialog"); | |
var shouldCancel = true; | |
if (shouldCancel) { | |
console.log("displaying confirmation dialog"); | |
e.preventDefault(); // this will display the confirmation dialog | |
} | |
// Chrome requires returnValue to be set | |
e.returnValue = ""; | |
}); | |
window.addEventListener("unload", function(event) { | |
// user confirmed they are sure | |
// perform cleanup | |
console.log("cleaning up"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment