Skip to content

Instantly share code, notes, and snippets.

@joeybaker
Created October 15, 2013 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeybaker/6999134 to your computer and use it in GitHub Desktop.
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.
// 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