--- title: BeforeInstallPrompt slug: Web/API/BeforeInstallPromptEvent tags: - PWA - beforeinstallprompt - 添加到主屏幕 - 添加快捷方式 translation_of: Web/API/BeforeInstallPromptEvent ---
{{ ApiRef() }} {{ Non-standard_header }}
在一个用户被提示”安装“一个网站到移动设备的一个主屏幕之前, BeforeInstallPromptEvent
被{{domxref("Window.onbeforeinstallprompt")}} 处理程序触发。
该接口继承自{{domxref("Event")}}接口。
{{InheritanceDiagram(700, 60, 20)}}
BeforeInstallPromptEvent
.继承自父类,{{domxref("Event")}}.
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); });
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support |
{{CompatChrome(44.0)}} [1] |
{{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
prompt() method. |
{{CompatChrome(45.0)}} [1] | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | {{ CompatNo() }} |
{{CompatChrome(44.0)}} [1] |
{{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} |
{{CompatChrome(44.0)}} [1] |
prompt() method. |
{{ CompatNo() }} | {{CompatChrome(45.0)}} [1] | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{ CompatNo() }} | {{CompatChrome(45.0)}} [1] |
[1] Behind the flagchrome://flags/#bypass-app-banner-engagement-checks