Skip to content

Instantly share code, notes, and snippets.

@itsmethemojo
Created May 17, 2016 07:08
Show Gist options
  • Save itsmethemojo/8d602a175a3c7ec9e72ec4ebc8880ad7 to your computer and use it in GitHub Desktop.
Save itsmethemojo/8d602a175a3c7ec9e72ec4ebc8880ad7 to your computer and use it in GitHub Desktop.
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