非标准
该特性是非标准的,请尽量不要在生产环境中使用它!
在一个用户被提示”安装“一个网站到移动设备的一个主屏幕之前, BeforeInstallPromptEvent
被Window.onbeforeinstallprompt
处理程序触发。
该接口继承自Event
接口。
构造器
new window.BeforeInstallPromptEvent(name, eventInitOptions)
- 创建一个新的
BeforeInstallPromptEvent
.
属性
继承自父类,Event
.
BeforeInstallPromptEvent.platform
只读- 返回一个包含了调度事件的平台(s)的
DOMString
数组。这是为希望向用户提供版本选择的user agent提供的,例如,“web”或“play”允许用户在web版本或Android版本之间进行选择。 BeforeInstallPromptEvent.userChoice
只读- 返回一个可以解析为
DOMString
的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); });
浏览器兼容性
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 |
44.0 [1] |
未实现 | 未实现 | 未实现 | 未实现 |
prompt() method. |
45.0 [1] | 未实现 | 未实现 | 未实现 | 未实现 |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | 未实现 |
44.0 [1] |
未实现 | 未实现 | 未实现 | 未实现 |
44.0 [1] |
prompt() method. |
未实现 | 45.0 [1] | 未实现 | 未实现 | 未实现 | 未实现 | 45.0 [1] |
[1] Behind the flagchrome://flags/#bypass-app-banner-engagement-checks