BeforeInstallPrompt

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!

在一个用户被提示”安装“一个网站到移动设备的一个主屏幕之前,BeforeInstallPromptEventWindow.onbeforeinstallprompt 处理程序触发。

该接口继承自Event接口。

must be a string

构造器

new window.BeforeInstallPromptEvent(name, eventInitOptions)

创建一个新的 BeforeInstallPromptEvent.

属性

继承自父类,Event.

BeforeInstallPromptEvent.platform 只读

返回一个包含了调度事件的平台(s)的 DOMString 数组。这是为希望向用户提供版本选择的 user agent 提供的,例如,“web”或“play”允许用户在 web 版本或 Android 版本之间进行选择。

BeforeInstallPromptEvent.userChoice 只读

返回一个可以解析为 DOMStringPromise ,其值为 '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);
});

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
BeforeInstallPromptEvent
ExperimentalNon-standard
BeforeInstallPromptEvent() constructor
ExperimentalNon-standard
platforms
ExperimentalNon-standard
prompt
ExperimentalNon-standard
userChoice
ExperimentalNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Has more compatibility info.