Created
February 26, 2012 21:52
-
-
Save glasner/1919166 to your computer and use it in GitHub Desktop.
AJAX on beforeunload for Chrome
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
sleep = (duration) -> | |
milliseconds = -> new Date().getTime() | |
start = milliseconds() | |
runningFor = milliseconds() - start | |
while runningFor < duration | |
runningFor = milliseconds() - start | |
$('div') # has to actually do something for it to work | |
window.addEventListener 'beforeunload', (e) -> | |
# make *sync* ajax call | |
sleep 1000 | |
return undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the beforeunload handler times out, Chrome will run previous code but not show the "Do you want to leave" dialog.