Created
January 22, 2013 22:05
-
-
Save zerolab/4598966 to your computer and use it in GitHub Desktop.
Example usage of onbeforeunload().
Used extensively in GMail, Google Docs, CodePen etc when there are unsaved changes.
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
// Pseudo code for using onbeforeunload() | |
$(window).on('unsaved', function(event) { | |
window.onbeforeunload = function() { | |
return "SOMETHING BAD if you navigate away."; | |
} | |
}).on("save", function(event) { | |
window.onbeforeunload = void(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment