Javascript: wait until ajax request finishes to close page [duplicate]
Edit Based on your comment below, a revised answer: If you want to block until a previously-initiated request completes, you can do it like this: window.onbeforeunload = function(event) { var s; event = event || window.event; if (requestsPending > 0) { s = “Your most recent changes are still being saved. ” + “If you … Read more