I have the following code to handle to prompt user in case of unsaved form data but this code also showing alert in case of click of submit button
$(document).ready(function () {
var _isDirty = false;
$(":input").live("change", function () {
_isDirty = true;
});
$(':[type=submit]').live('click', function () {
_isDirty = false;
});
window.onbeforeunload = function () {
if (_isDirty) {
return 'You have made changes to data on this page. If you navigate away from this page without first saving your data, the changes will be lost.';
}
else {
return nul开发者_高级运维l;
}
}
}
onbeforeunload
has a quirk that if you return anything, even null, it will throw the alert. Try removing the else clause else {return null;}
, and it should stop showing up.
Follow this post for your answer.
精彩评论