Php 如何加上「;“添加到主屏幕”;作为移动视图中的弹出窗口
当“添加到主屏幕”在移动视图上打开时,我想在网站上显示一个弹出窗口。我使用了核心php、jquery来构建我的网站您需要满足上面提到的条件,其中也有使用示例Php 如何加上「;“添加到主屏幕”;作为移动视图中的弹出窗口,php,jquery,Php,Jquery,当“添加到主屏幕”在移动视图上打开时,我想在网站上显示一个弹出窗口。我使用了核心php、jquery来构建我的网站您需要满足上面提到的条件,其中也有使用示例 您需要将manifest.json文件添加到根目录,其中包括: 简称 图标必须包括192px和512px大小的图标 启动url 显示器必须是全屏、独立或 最小用户界面 您的网站必须在https上运行 具有具有fetch的服务工作人员 若您满足所有这些条件,web应该在安装前触发提示事件,在该事件中显示一些按钮(下例中为btnAdd)或栏
- 简称
- 图标必须包括192px和512px大小的图标
- 启动url
- 显示器必须是全屏、独立或 最小用户界面
let deferredPrompt;
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 notify the user they can add to home screen
btnAdd.style.display = 'block';
});
//show prompt on 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;
});
});
虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-@Shree我编辑了我的帖子,并添加了更多具体信息的示例。谢谢。我收回国旗。