From bc10ccbf6ab1dc50197144c9229ea26ddb435fe4 Mon Sep 17 00:00:00 2001 From: LiangSenCheng <> Date: Tue, 29 Jun 2021 08:49:13 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=AE=89=E8=A3=85=E6=8C=89=E9=92=AE=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 22 ++++++++++++++++++++-- manifest.json | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index ae4faac..9003ece 100644 --- a/index.html +++ b/index.html @@ -21,15 +21,33 @@ }) } + var deferredPrompt = null; + + // 判断用户是否安装此应用:beforeinstallprompt + window.addEventListener("beforeinstallprompt", e => { + e.preventDefault(); + deferredPrompt = e; + console.log('beforeinstallprompt'); + }); + + window.addEventListener("appinstalled", () => { + deferredPrompt = null; + console.log('appinstalled'); + }); + + function addToDesktop() { + console.log('addToDesktop'); + deferredPrompt.prompt(); + deferredPrompt = null; + } -
- + diff --git a/manifest.json b/manifest.json index ad93f05..0851b62 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "short_name": "图片加水印", "theme_color": "#FFFFFF", "background_color": "#FFFFFF", - "display": "fullscreen", + "display": "standalone", "scope": "/", "start_url": "/", "icons": [