From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/beforeinstallpromptevent/index.html | 129 +++++++++++++++++++++ .../api/beforeinstallpromptevent/prompt/index.html | 106 +++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 files/zh-cn/web/api/beforeinstallpromptevent/index.html create mode 100644 files/zh-cn/web/api/beforeinstallpromptevent/prompt/index.html (limited to 'files/zh-cn/web/api/beforeinstallpromptevent') diff --git a/files/zh-cn/web/api/beforeinstallpromptevent/index.html b/files/zh-cn/web/api/beforeinstallpromptevent/index.html new file mode 100644 index 0000000000..914a63588a --- /dev/null +++ b/files/zh-cn/web/api/beforeinstallpromptevent/index.html @@ -0,0 +1,129 @@ +--- +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)}}

+ +

构造器

+ +
+
{{domxref("new window.BeforeInstallPromptEvent(name, eventInitOptions)")}}
+
创建一个新的 BeforeInstallPromptEvent.
+
+ +

属性

+ +

继承自父类,{{domxref("Event")}}.

+ +
+
{{domxref("BeforeInstallPromptEvent.platform")}} {{readonlyinline}}
+
返回一个包含了调度事件的平台(s)的 {{domxref("DOMString")}} 数组。这是为希望向用户提供版本选择的user agent提供的,例如,“web”或“play”允许用户在web版本或Android版本之间进行选择。
+
{{domxref("BeforeInstallPromptEvent.userChoice")}} {{readonlyinline}}
+
返回一个可以解析为 {{domxref("DOMString")}} 的 {{jsxref("Promise")}} ,其值为 'installed' 或 'dismissed',用以判断用户是否选择安装该PWA。
+
+ +

方法

+ +
+
{{domxref("BeforeInstallPromptEvent.prompt()")}} 
+
立即弹出安装提示。允许开发者按照自己选择的时间弹出安装提示。该方法返回 {{jsxref("Promise")}}。
+
+ +

例子

+ +
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() }}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support +

{{CompatChrome(44.0)}} [1]

+
{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
prompt() method.{{CompatChrome(45.0)}} [1]{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome 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

diff --git a/files/zh-cn/web/api/beforeinstallpromptevent/prompt/index.html b/files/zh-cn/web/api/beforeinstallpromptevent/prompt/index.html new file mode 100644 index 0000000000..265147affe --- /dev/null +++ b/files/zh-cn/web/api/beforeinstallpromptevent/prompt/index.html @@ -0,0 +1,106 @@ +--- +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}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(45.0)}} [1]    
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}}{{CompatChrome(45.0)}} [1]     {{CompatChrome(45.0)}} [1]
+
+ +

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

-- cgit v1.2.3-54-g00ecf