Skip to content

Instantly share code, notes, and snippets.

@limhenry

limhenry/a2hs.js Secret

Last active August 10, 2018 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save limhenry/3da969c5abdc4d782055294d9a2390b7 to your computer and use it in GitHub Desktop.
Save limhenry/3da969c5abdc4d782055294d9a2390b7 to your computer and use it in GitHub Desktop.
var installPromptEvent;
var btnInstall = document.querySelector('#install');
window.addEventListener('beforeinstallprompt', function (event) {
event.preventDefault();
installPromptEvent = event;
btnInstall.removeAttribute('disabled');
});
btnInstall.addEventListener('click', function () {
btnInstall.setAttribute('disabled', '');
installPromptEvent.prompt();
installPromptEvent.userChoice.then((choice) => {
if (choice.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
installPromptEvent = null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment