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’t prevent the calling of unbeforeunload, but using a global flag variable, you can control whether it displays a warning.
in the document, add the script:
in the submit event, add:
the definition of the event, change to:
through
warn_on_unload, you can now switch the warning message on or off at will.