javascript - Defer Web Install Banner -


according developers.google.com possible defer web app install banner, have been able cancel completely.

window.addeventlistener('beforeinstallprompt', function(e) {   console.log('beforeinstallprompt event fired');   e.preventdefault();   return false; }); 

one use case defer prompt until later in page lifecycle, example after user has performed action, or hit bottom of page (something indicate engaging site).

how possible defer web-app banner?

try check documentation, if can you.

here complete code use in deferring prompt.

var deferredprompt;  window.addeventlistener('beforeinstallprompt', function(e) {   console.log('beforeinstallprompt event fired');   e.preventdefault();    // stash event can triggered later.   deferredprompt = e;    return false; });  btnsave.addeventlistener('click', function() {   if(deferredprompt !== undefined) {     // user has had postive interaction our app , chrome     // has tried prompt previously, let's show prompt.     deferredprompt.prompt();      // follow user has done prompt.     deferredprompt.userchoice.then(function(choiceresult) {        console.log(choiceresult.outcome);        if(choiceresult.outcome == 'dismissed') {         console.log('user cancelled home screen install');       }       else {         console.log('user added home screen');       }        // no longer need prompt.  clear up.       deferredprompt = null;     });   } }); 

for more information, check link.


Comments