feat: 添加手动触发安装按钮;

This commit is contained in:
LiangSenCheng 2021-06-29 08:49:13 +00:00
parent e87c2c4576
commit bc10ccbf6a
2 changed files with 21 additions and 3 deletions

View File

@ -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;
}
</script> </script>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<script src="./index.js"></script> <script src="./index.js"></script>
<button onclick="addToDesktop()">添加到桌面</button>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@
"short_name": "图片加水印", "short_name": "图片加水印",
"theme_color": "#FFFFFF", "theme_color": "#FFFFFF",
"background_color": "#FFFFFF", "background_color": "#FFFFFF",
"display": "fullscreen", "display": "standalone",
"scope": "/", "scope": "/",
"start_url": "/", "start_url": "/",
"icons": [ "icons": [