Created
September 20, 2017 00:41
-
-
Save hexsprite/836038bddcc3a5eb54e7009421e10787 to your computer and use it in GitHub Desktop.
Show browser confirmation when Meteor methods are pending in the queue
This file contains hidden or 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
window.addEventListener('beforeunload', function (e) { | |
const hasOutstandingRequests = | |
Meteor.connection._outstandingMethodBlocks.length | |
if (hasOutstandingRequests) { | |
// Note: modern browsers don't show a custom message but still confirm | |
const confirmationMessage = | |
'WARNING: There are outstanding requests. Really close this window? If you do you may lose data!' | |
e.returnValue = confirmationMessage // Gecko, Trident, Chrome 34+ | |
return confirmationMessage // Gecko, WebKit, Chrome <34 | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment