I have this little piece of code:
Call unbind using the beforeunload event handler:
beforeunload
$('form#someForm').submit(function() { $(window).unbind('beforeunload'); });
To prevent the form from being submitted, add the following line:
return false;