BeforeInstallPromptEvent:prompt() 方法
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!
BeforeInstallPromptEvent
接口的 prompt()
方法使开发者能够在自己选择的时间展示安装提示。通常,这将在应用程序自定义安装界面的事件处理器中被调用。
此方法必须在用户操作(如按钮点击)的事件处理器中调用,并且对于给定的 BeforeInstallPromptEvent
实例只能调用一次。
语法
js
prompt()
参数
无。
返回值
一个解析为包含以下属性的对象的 Promise
:
outcome
实验性 非标准-
一个字符串,表示用户是否选择了安装应用。此字符串必须是以下值之一:
"accepted"
:用户已安装该应用。"dismissed"
:用户未安装该应用。
platform
实验性 非标准-
如果用户选择安装应用,此参数为一个字符串,表示所选平台的名称,该名称是
BeforeInstallPromptEvent.platforms
属性的值之一。如果用户选择不安装应用,此参数则为空字符串。
示例
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
prompt |
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.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
- 制作可安装的 PWA
- web.developers.google.cn 上的如何为应用提供安装体验(2021)