Window.onbeforeinstallprompt - Web API 接口参考 编辑
Window.onbeforeinstallprompt
属性是一个事件处理程序, 用于处理一个beforeinstallprompt
, 当一个Web清单存在时,它将在移动设备上发送,但是在提示用户将网站保存到主屏幕之前。
句法
window.addEventListener("beforeinstallprompt", function(event) { ... }); window.onbeforeinstallprompt = function(event) { ...};
范例
The following example uses the beforeinstallprompt function to verify that it is an appropriate time to display an installation prompt to the user. If it is not, the event is redispatched.
let isTooSoon = true;
window.addEventListener("beforeinstallprompt", function(e) {
if (isTooSoon) {
e.preventDefault(); // Prevents prompt display
// Prompt later instead:
setTimeout(function() {
isTooSoon = false;
e.prompt(); // Shows prompt
}, 10000);
}
// The event was re-dispatched in response to our request
// ...
});
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 45.0 [1] | 未实现 | 未实现 | 未实现 | 未实现 |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | 未实现 | 45.0 [1] | 未实现 | 未实现 | 未实现 | 未实现 | 45.0 [1] |
[1] Behind the flagchrome://flags/#bypass-app-banner-engagement-checks
规范
Specification | Status | Comment |
---|---|---|
Web App Manifest Window.onbeforeinstallprompt | Working Draft | Initial specification. |
也可以看看
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论