Skip to content

Instantly share code, notes, and snippets.

@samwilson
Created November 8, 2012 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwilson/4037247 to your computer and use it in GitHub Desktop.
Save samwilson/4037247 to your computer and use it in GitHub Desktop.
Prompt when leaving unsaved POST forms
$("form[method='post'] :input").change(function() {
window.onbeforeunload = function(){
return true; // Prompt if any input has changed
};
});
$("form[method='post']").submit(function() {
window.onbeforeunload = null; // Only remove the prompt if it's the submit button
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment