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