Last active
August 29, 2015 14:24
-
-
Save jdavidbakr/cda58099a5f64282cf06 to your computer and use it in GitHub Desktop.
JavaScript: Page change warning - alerts the user before allowing the window to close
This file contains hidden or 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
var PageChangeWarning = { | |
unload_message: "You have unsaved changes on this page.", | |
display_warning: function() { | |
return this.unload_message; | |
}, | |
change_made: function() { | |
window.onbeforeunload = this.display_warning.bind(this); | |
}, | |
saved: function() { | |
window.onbeforeunload = null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment