Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let deferredInstallPrompt = null;
- const installButton = document.getElementById('butInstall');
- installButton.addEventListener('click', installPWA);
- window.addEventListener('beforeinstallprompt', saveBeforeInstallPromptEvent);
- function saveBeforeInstallPromptEvent(evt) {
- deferredInstallPrompt = evt;
- installButton.removeAttribute('hidden');
- }
- function installPWA(evt) {
- // CODELAB: Add code show install prompt & hide the install button.
- deferredInstallPrompt.prompt();
- // Escondendo botão
- evt.srcElement.setAttribute('hidden', true);
- //Interceptando se o usuário aceitou ou não a instalação
- deferredInstallPrompt.userChoice
- .then((choice) => {
- if (choice.outcome === 'accepted') {
- console.log('Usuário aceitou', choice);
- } else {
- console.log('Usuário não aceitou', choice);
- }
- deferredInstallPrompt = null;
- });
- }
- window.addEventListener('appinstalled', logAppInstalled);
- function logAppInstalled(evt) {
- console.log('Aplicativo já está instalado.', evt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement