--- title: BeforeInstallPromptEvent.prompt() slug: Web/API/BeforeInstallPromptEvent/prompt tags: - BeforeInstallPromptEvent - BeforeInstallPromptEvent.prompt() translation_of: Web/API/BeforeInstallPromptEvent/prompt ---

{{APIRef("")}}

{{SeeCompatTable}}

{{domxref("BeforeInstallPromptEvent")}} 接口的 prompt()方法允许一个开发人员在自己选择的一个时间显示安装提示。

句法

BeforeInstallPromptEvent.prompt()

参数

返回

一个空的 {{jsxref("Promise")}}.

范例

let isTooSoon = true;
window.addEventListener("beforeinstallprompt", function(e) {
  if (isTooSoon) {
    e.preventDefault(); // Prevents prompt display
    // Prompt later instead:
    setTimeout(function() {
      isTooSoon = false;
      e.prompt(); // Throws if called more than once or default not prevented
    }, 10000);
  }

  // The event was re-dispatched in response to our request
  // ...
});

规范

This method is not part of a specification.

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(45.0)}} [1]        
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatChrome(45.0)}} [1]           {{CompatChrome(45.0)}} [1]

[1] Behind the flag: chrome://flags/#bypass-app-banner-engagement-checks