Skip to content

Instantly share code, notes, and snippets.

@hexsprite
Created September 20, 2017 00:41
Show Gist options
  • Save hexsprite/836038bddcc3a5eb54e7009421e10787 to your computer and use it in GitHub Desktop.
Save hexsprite/836038bddcc3a5eb54e7009421e10787 to your computer and use it in GitHub Desktop.
Show browser confirmation when Meteor methods are pending in the queue
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