1
2
3
4
5
6
7
8
//https://stackoverflow.com/a/21061009/1320686
$('#form').data('serialize',$('#form').serialize()); // On load save form current state
$(window).bind('beforeunload', function(e){
if($('#form').serialize()!=$('#form').data('serialize'))return true;
else e=null; // i.e; if form state change show warning box, else don't show it.
});
origin - http://www.pipiscrew.com/?p=8812 before-leaving-the-page