Add to Home screen javascript call?

I have successfully migrated my older mobile site from framework7 v1 to v5! I’m pleased that everything is working despite all the changes made (putting pages into router, rewriting some JS to put in methods).

So I finally tested the fresh site with phones instead of browser developer mode and noted the Add to Home screen toast at the bottom of android phones which is a nice touch but I can’t get it back after I hit cancel. I tried finding it in node_modules but can’t find the javascript function to call.

What’s the name of the function?

Thanks

It is a Android’s system prompt modal. It is not done by some JavaScript. And i am not sure is it possible to show it again after you discarded it, but you can check this article https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Add_to_home_screen

1 Like

Thanks for the info, and after reading that, I got it working with the following code. Optional preventdefault() prevents first prompt firing and the event is then saved for later calling event.prompt(). Hope others find this helpful.

on: {
      pageInit: function () {
        window.addEventListener('beforeinstallprompt', function(event) {
         //  event.preventDefault();
          window.installPromptEvent = event;
        });
      }
    },

callInstallPrompt() {
      if (window.installPromptEvent !== undefined) { 
       window.installPromptEvent.prompt(); }
   }

1 Like