Created
May 17, 2016 07:08
-
-
Save itsmethemojo/8d602a175a3c7ec9e72ec4ebc8880ad7 to your computer and use it in GitHub Desktop.
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
var deferredPromptEvent; | |
window.addEventListener('beforeinstallprompt', function(e) { | |
e.preventDefault(); | |
deferredPromptEvent = e; | |
return false; | |
}); | |
// and in the moment your condition is fulfilled | |
// check if the prompt had been triggered | |
if(deferredPromptEvent !== undefined && deferredPromptEvent) { | |
// show message | |
deferredPromptEvent.prompt(); | |
// do something on the user choice | |
deferredPromptEvent.userChoice.then(function(choiceResult) { | |
if(choiceResult.outcome != 'dismissed') { | |
} | |
// finally remove it | |
deferredPromptEvent = null; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment