Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript add to home screen button

let deferredPrompt;
const addBtn = document.querySelector('.add-button');
addBtn.style.display = 'none';

window.addEventListener('beforeinstallprompt', (e) => {
  // Prevent Chrome 67 and earlier from automatically showing the prompt
  e.preventDefault();
  // Stash the event so it can be triggered later.
  deferredPrompt = e;
  // Update UI to notify the user they can add to home screen
  addBtn.style.display = 'block';

  addBtn.addEventListener('click', (e) => {
    // hide our user interface that shows our A2HS button
    addBtn.style.display = 'none';
    // Show the prompt
    deferredPrompt.prompt();
    // Wait for the user to respond to the prompt
    deferredPrompt.userChoice.then((choiceResult) => {
        if (choiceResult.outcome === 'accepted') {
          console.log('User accepted the A2HS prompt');
        } else {
          console.log('User dismissed the A2HS prompt');
        }
        deferredPrompt = null;
      });
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: upload image postman 
Javascript :: replacing a value in string using aregular expression pyhton 
Javascript :: javascript abstract class 
Javascript :: use css child selector inside js 
Javascript :: Javascript number Count up 
Javascript :: classlist remove multiple classes 
Javascript :: create neact native app 
Javascript :: every() method 
Javascript :: shift and unshift js 
Javascript :: get total pairs from integer array javascript 
Javascript :: fingerprint js 
Javascript :: JavaScript then() method 
Javascript :: javascript string add new line 
Javascript :: crypto in node js 
Javascript :: date in javascript 
Javascript :: getrecord lwc 
Javascript :: what is after.js 
Javascript :: how to give icon in input type file react 
Javascript :: split in javascript 
Javascript :: hashing passwords with bcrypt 
Javascript :: audio element javascript 
Javascript :: Remove items from an index position 
Javascript :: Country API JavaScript Code 
Javascript :: best node js orm for mysql 
Javascript :: javascript unshift 
Javascript :: how to copy array of objects in javascript 
Javascript :: next js css background image 
Javascript :: push javascript 
Javascript :: mongodb find element in array 
Javascript :: sum of an array 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =