Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

449
Visualizações
how to add custom install button for pwa

i want to add custom install button for my progressive web app within the site. i red many articles and tried the answer provided by them. they use beforeinstallprompt

let deferredPrompt;

window.addEventListener('beforeinstallprompt', (e) => {
    deferredPrompt = e;
});

but the problem i am facing is i want the button to directly installed the pwa instead of triggering the installation prompt. is it possible, if so how can i achieve that. thanks you in advance.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The answer is, you can't. According to the manifest spec:

By design, this specification does not provide developers with an explicit API to "install" a web application.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try below code,

Step 1 - Create button or any controller

<button id="installApp">Install</button>

Step 2 - Add below js code in your scripts noy in serviceworker

let deferredPrompt;
    window.addEventListener('beforeinstallprompt', (e) => {
        deferredPrompt = e;
    });

    const installApp = document.getElementById('installApp');
    installApp.addEventListener('click', async () => {
        if (deferredPrompt !== null) {
            deferredPrompt.prompt();
            const { outcome } = await deferredPrompt.userChoice;
            if (outcome === 'accepted') {
                deferredPrompt = null;
            }
        }
    });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda