With this simple jQuery function, you can notify a user if they’ve made any un-saved changes to a form field – and give them a chance to save or discard those changes. I was recently able to try this out on a work project and it is working beautifully.
I have a feeling THIS will come in very handy for a variety of projects.
var isDirty = false;
var msg = 'You haven't saved your changes.';
$(document).ready(function(){
$(':input').change(function(){
if(!isDirty){
isDirty = true;
}
});
window.onbeforeunload = function(){
if(isDirty) {
return msg;
}
};
});
No comments:
Post a Comment