How can I prevent onbeforeunload from being called when clicking the submit button?
$(document).ready(function()
{
$('input:text,input:checkbox,input:radio,textarea,select').one('change', function()
{
//('BODY').attr('onbeforeunload',"return 'Leaving this page will cause any unsaved data to be lost.';");
if(
window.onbeforeunload = function() { return 'You have unsaved changes!'; }
});
});
you can use .on()
to bind onbeforeunload and then use .off()
to unbind it in form submission, short and sweet
$(document).ready(function () {
$(window).on('beforeunload', function(){
return "You have unsaved changes!";
});
$(document).on("submit", "form", function(event){
$(window).off('beforeunload');
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With