Skip to content

Instantly share code, notes, and snippets.

@limhenry

limhenry/a2hs.js Secret

Last active August 10, 2018 03:38
Embed
What would you like to do?
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