BeforeInstallPrompt

 

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

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

该接口继承自Event接口。

Constructor

new window.BeforeInstallPromptEvent(name, eventInitOptions)
Creates a new BeforeInstallPromptEvent.

Properties

Inherits properties from its parent, Event.

BeforeInstallPromptEvent.platform 只读
Returns a DOMString containing the platform on which the event was dispatched.
BeforeInstallPromptEvent.userChoice 只读
Returns a Promise that resolves to a DOMString containing either 'installed' or 'dismissed'.

Methods

BeforeInstallPromptEvent.prompt() 
Allows a developer to show the install prompt at a time of their own choosing. This method returns a  Promise.

Example

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); 
});

Browser compatibility

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