I am using a javascript to check for unsaved changes, but when editing, adding a new line or refreshing the grid, the unsaved changes message box appears. how can i stop this? javascript code below:
<script type="text/javascript">
// Store form state at page load
var initial_form_state = $('#form1').serialize();
// Store form state after form submit
$('#form1').submit(function () {
initial_form_state = $('#form1').serialize();
});
// Check form changes before leaving the page and warn user if needed
$(window).bind('beforeunload', function (e) {
var form_state = $('#form1').serialize();
if (initial_form_state != form_state) {
var message = "You have unsaved changes on this page. Do you want to leave this page and discard your changes or stay on this page?";
e.returnValue = message; // Cross-browser compatibility (src: MDN)
return message;
}
});
</script>