Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

448
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda