Created
October 15, 2013 21:42
-
-
Save joeybaker/6999134 to your computer and use it in GitHub Desktop.
Show the user a warning before they leave the page if AJAX has yet to complete.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if the user attempts to navigate away from the page before ajax is complete, warn. | |
$.ajaxPrefilter(function(/*options, originalOptions, jqXHR*/) { | |
window.onbeforeunload = function(){ | |
return 'Please allow ajax to complete' | |
} | |
}) | |
// remove the warning when AJAX is done | |
$(document).ajaxComplete(function(){ | |
window.onbeforeunload = void 0 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment