Skip to content
Advertisement

Pwa installation own button installation in JS + HTML + CSS

I know how to do a pwa integration and the browser proposes the installation with the message “Add — to the home screen”. My wish is as follows: I would like to set up on the integrated PWA website a personalized button l “Install mobile version” in HTML so that my users can install the progressive web app as needed, especially when they wish. They will not necessarily wait for the browser to offer them the installation. I have already done the PWA integration and the browser already offers the installation. Problem is, I don’t really know how to go about my permanent web app progressive install button in html + javascript that users will see on my website outside of what the browser offers.

Here is my service-worker.js and my index.html

JavaScript
JavaScript

Advertisement

Answer

Your code looks fine, you only need to implement this part: https://stackoverflow.com/a/64727286/8716572

First you need to use this code to listen to the beforeinstallprompt event:

JavaScript

Then you need to add the event listener to your button:

JavaScript
Advertisement