[英]Adding mobile web app to home screen using button
I'm trying to add app to home screen via button located in "settings" page of my HTML5 mobile web app (Notice: It is working if I'm trying to add it via Chrome menu). 我正在尝试通过HTML5移动网络应用程序“设置”页面上的按钮将应用程序添加到主屏幕(注意:如果我想通过Chrome菜单添加应用程序,则可以使用)。
I've set up all of these steps: 我已经完成所有这些步骤:
Currently I'm debugging it via Chrome Dev tools and listening to beforeinstallprompt
with that code from official docs. 目前,我正在通过Chrome Dev工具进行调试,并使用官方文档中的代码收听
beforeinstallprompt
。
<script>
let deferredPrompt;
window.addEventListener('beforeinstallprompt', function(event) {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
});
// Installation must be done by a user gesture! Here, the button click
btnAdd.addEventListener('click', (e) => {
// hide our user interface that shows our A2HS button
btnAdd.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;
});
});
</script>
How to catch event on /home
page, and pass it to /settings
page so I could fire the event via (onClick)
event? 如何在
/home
页面上捕获事件,并将其传递到/settings
页面,以便我可以通过(onClick)
事件触发该事件?
Currently I'm using: 目前,我正在使用:
Angular CLI: 6.1.4 角CLI:6.1.4
Node: 8.11.4 节点:8.11.4
OS: win32 x64 操作系统:win32 x64
将其保存到全局( window
)对象(或具有全局访问权限的其他位置)以及事件处理程序调用window.deferredPrompt.prompt()
/settings
页面上吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.