BeforeInstallPromptEvent

BeforeInstallPromptEvent is fired at the Window.onbeforeinstallprompt handler before a user is prompted to "install" a web site to a home screen on mobile.

This interface inherits from the Event 接口。

构造函数

BeforeInstallPromptEvent()
创建新的 BeforeInstallPromptEvent .

特性

Inherits properties from its parent, Event .

BeforeInstallPromptEvent.platforms 只读
Returns an array of DOMString items containing the platforms on which the event was dispatched. This is provided for user agents that want to present a choice of versions to the user such as, for example, "web" or "play" which would allow the user to chose between a web version or an Android version.
BeforeInstallPromptEvent.userChoice 只读
返回 Promise that resolves to a DOMString containing either "accepted" or "dismissed".

方法

BeforeInstallPromptEvent.prompt()
Allows a developer to show the install prompt at a time of their own choosing. This method returns a 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(choiceResult) {
    console.log(choiceResult.outcome); // either "accepted" or "dismissed"
  }, handleError);
});
					

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
BeforeInstallPromptEvent
非标
Chrome 45 Edge ≤79 Firefox No IE No Opera No Safari No WebView Android 45 Chrome Android 45 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 5.0
BeforeInstallPromptEvent() 构造函数
非标
Chrome 45 Edge ≤79 Firefox No IE No Opera No Safari No WebView Android 45 Chrome Android 45 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 5.0
platforms
非标
Chrome 45 Edge ≤79 Firefox No IE No Opera No Safari No WebView Android 45 Chrome Android 45 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 5.0
prompt
非标
Chrome 45 Edge ≤79 Firefox No IE No Opera No Safari No WebView Android 45 Chrome Android 45 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 5.0
userChoice
非标
Chrome 45 Edge ≤79 Firefox No IE No Opera No Safari No WebView Android 45 Chrome Android 45 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android 5.0

图例

完整支持
完整支持
不支持
不支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
非标。预期跨浏览器支持较差。