From 50da22ca655865b7fb9bf80f012b2531be6ed9ce Mon Sep 17 00:00:00 2001 From: libai <libai@yazhai.co> Date: Wed, 23 Nov 2022 15:55:48 +0800 Subject: [PATCH] 测试 --- mTest/index.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/mTest/index.js b/mTest/index.js index 873f266..463b68b 100644 --- a/mTest/index.js +++ b/mTest/index.js @@ -15,26 +15,29 @@ 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'; + setTimeout(function() { + // 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', () => { + // 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; + }); + }); + }, 5000); - addBtn.addEventListener('click', () => { - // 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; - }); - }); }); \ No newline at end of file -- libgit2 0.25.0