Skip to content

Instantly share code, notes, and snippets.

@zerolab
Created January 22, 2013 22:05
Show Gist options
  • Save zerolab/4598966 to your computer and use it in GitHub Desktop.
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.
// 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