-
-
Save limhenry/3da969c5abdc4d782055294d9a2390b7 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 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