Open alanhe421 opened 1 year ago
let deferredPrompt;
const installApp = document.getElementById('installApp');
window.addEventListener('beforeinstallprompt', (e) => {
installApp.style.display = 'block';
deferredPrompt = e;
});
installApp.addEventListener('click', async () => {
if (deferredPrompt !== null) {
deferredPrompt.prompt();
const {outcome} = await deferredPrompt.userChoice;
if (outcome === 'accepted') {
deferredPrompt = null;
}
}
});
配置项说明
display
minimal-ui
standalone
name/short_name/display配置修改更新
比如name修改,再浏览器重启访问网站是会提示更新,但比如display配置修改,重启浏览器访问app,不会提示,直接会使用最新的。
theme_color
控制title bar部分
动态修改theme_color,可以通过动态修改
<meta name="theme-color" content="#0066ff"/>
来解决调试
shortcuts
MacOS/iOS目前还不支持. Windws/Android效果可能如下,目前来看该设置还没有普遍使用
chrome隐私模式下不支持pwa安装提示,也不支持serviceWorker提示