在一个用户被提示”安装“一个网站到移动设备的一个主屏幕之前,BeforeInstallPromptEvent 被 Window.onbeforeinstallprompt 处理程序触发。
该接口继承自Event接口。
构造器
- new window.BeforeInstallPromptEvent(name, eventInitOptions)
- : 创建一个新的
BeforeInstallPromptEvent.
- : 创建一个新的
属性
继承自父类,Event.
- BeforeInstallPromptEvent.platform
- : 返回一个包含了调度事件的平台(s)的 String 数组。这是为希望向用户提供版本选择的 user agent 提供的,例如,“web”或“play”允许用户在 web 版本或 Android 版本之间进行选择。
- BeforeInstallPromptEvent.userChoice
- : 返回一个可以解析为 String 的 Promise ,其值为 'installed' 或 'dismissed',用以判断用户是否选择安装该 PWA。
方法
- BeforeInstallPromptEvent.prompt()
- : 立即弹出安装提示。允许开发者按照自己选择的时间弹出安装提示。该方法返回 Promise。
例子
window.addEventListener("beforeinstallprompt", function(e) {
// log the platforms provided as options in an install prompt
console.log(e.platforms); // e.g., ["web", "android", "windows"]
e.userChoice.then(function(outcome) {
console.log(outcome); // either "installed", "dismissed", etc.
}, handleError);
});
浏览器兼容性
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
