From 3f5025eba18d07c319fee9d28e215d315ef5d1b2 Mon Sep 17 00:00:00 2001 From: MDN Date: Fri, 11 Mar 2022 00:14:44 +0000 Subject: [CRON] sync translated content --- .../window/beforeinstallprompt_event/index.html | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 files/zh-cn/web/api/window/beforeinstallprompt_event/index.html (limited to 'files/zh-cn/web/api/window/beforeinstallprompt_event') diff --git a/files/zh-cn/web/api/window/beforeinstallprompt_event/index.html b/files/zh-cn/web/api/window/beforeinstallprompt_event/index.html new file mode 100644 index 0000000000..b9f089174d --- /dev/null +++ b/files/zh-cn/web/api/window/beforeinstallprompt_event/index.html @@ -0,0 +1,67 @@ +--- +title: Window.onbeforeinstallprompt +slug: Web/API/Window/beforeinstallprompt_event +tags: + - Window.onbeforeinstallprompt + - beforeinstallprompt +translation_of: Web/API/Window/onbeforeinstallprompt +original_slug: Web/API/Window/onbeforeinstallprompt +--- +

{{ ApiRef() }}

+ +

Window.onbeforeinstallprompt 属性是一个事件处理程序, 用于处理一个{{event("beforeinstallprompt")}}, 当一个Web清单存在时,它将在移动设备上发送,但是在提示用户将网站保存到主屏幕之前。

+ +

句法

+ +
window.addEventListener("beforeinstallprompt", function(event) { ... });
+
+window.onbeforeinstallprompt = function(event) { ...};
+ +

范例

+ +

The following example uses the beforeinstallprompt function to verify that it is an appropriate time to display an installation prompt to the user. If it is not, the event is redispatched.

+ +
let isTooSoon = true;
+window.addEventListener("beforeinstallprompt", function(e) {
+  if (isTooSoon) {
+    e.preventDefault(); // Prevents prompt display
+    // Prompt later instead:
+    setTimeout(function() {
+      isTooSoon = false;
+      e.prompt(); // Shows prompt
+    }, 10000);
+  }
+
+  // The event was re-dispatched in response to our request
+  // ...
+});
+ +

浏览器兼容性

+ +{{Compat("api.Window.onbeforeinstallprompt")}} + +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Manifest', '#onbeforeinstallprompt-attribute', 'Window.onbeforeinstallprompt')}}{{Spec2('Manifest')}}Initial specification.
+ +

也可以看看

+ + -- cgit v1.2.3-54-g00ecf