-
-
Save russiann/c2f8ce6bfc86322627a3ef0f95f90b53 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
//referencia do prompt | |
var bannerInstall; | |
if ('serviceWorker' in navigator){ | |
navigator.serviceWorker | |
.register('sw.js') | |
.then(function () { | |
console.log('Service worker está registrado!'); | |
}); | |
} | |
//evento disparado para instalar a aplicacao | |
window.addEventListener('beforeinstallprompt', function(event) { | |
console.log('beforeinstallprompt disparado...'); | |
//prevenindo a instalacao e guardando a referencia | |
event.preventDefault(); | |
bannerInstall = event; | |
return false; | |
}); | |
// Controlando o banner de instalacao | |
var btnBannerInstall = document.querySelector('#enable-banner-install'); | |
function showBannerInstall(){ | |
if(bannerInstall){ | |
//exibindo o banner | |
bannerInstall.prompt(); | |
//verificando a escolha do usuario | |
bannerInstall.userChoice.then(function(choiceResult) { | |
if (choiceResult.outcome === 'dismissed') { | |
console.log('Usuario cancelou a instalacao'); | |
} else { | |
console.log('Usuario aceitou a instalacao'); | |
} | |
}); | |
} | |
bannerInstall = null; | |
} | |
//clique do botao | |
btnBannerInstall.addEventListener('click', showBannerInstall); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment