diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/beforeinstallpromptevent/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/beforeinstallpromptevent/index.html')
-rw-r--r-- | files/zh-cn/web/api/beforeinstallpromptevent/index.html | 129 |
1 files changed, 129 insertions, 0 deletions
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 +--- +<p>{{ ApiRef() }} {{ Non-standard_header }}</p> + +<p>在一个用户被提示”安装“一个网站到移动设备的一个主屏幕之前, <code><strong>BeforeInstallPromptEvent </strong></code> 被{{domxref("Window.onbeforeinstallprompt")}} 处理程序触发。</p> + +<p>该接口继承自{{domxref("Event")}}接口。</p> + +<p>{{InheritanceDiagram(700, 60, 20)}}</p> + +<h2 id="构造器">构造器</h2> + +<dl> + <dt>{{domxref("new window.BeforeInstallPromptEvent(name, eventInitOptions)")}}</dt> + <dd>创建一个新的 <code><strong>BeforeInstallPromptEvent</strong></code>.</dd> +</dl> + +<h2 id="属性">属性</h2> + +<p><em>继承自父类,{{domxref("Event")}}.</em></p> + +<dl> + <dt>{{domxref("BeforeInstallPromptEvent.platform")}} {{readonlyinline}}</dt> + <dd>返回一个包含了调度事件的平台(s)的 {{domxref("DOMString")}} 数组。这是为希望向用户提供版本选择的user agent提供的,例如,“web”或“play”允许用户在web版本或Android版本之间进行选择。</dd> + <dt>{{domxref("BeforeInstallPromptEvent.userChoice")}} {{readonlyinline}}</dt> + <dd>返回一个可以解析为 {{domxref("DOMString")}} 的 {{jsxref("Promise")}} ,其值为 'installed' 或 'dismissed',用以判断用户是否选择安装该PWA。</dd> +</dl> + +<h2 id="方法">方法</h2> + +<dl> + <dt>{{domxref("BeforeInstallPromptEvent.prompt()")}} </dt> + <dd>立即弹出安装提示。允许开发者按照自己选择的时间弹出安装提示。该方法返回 {{jsxref("Promise")}}。</dd> +</dl> + +<h2 id="例子">例子</h2> + +<pre class="notranslate">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); +}); +</pre> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{ CompatibilityTable() }}</p> + +<table> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td> + <p>{{CompatChrome(44.0)}} [1]</p> + </td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + <tr> + <td><code>prompt()</code> method.</td> + <td>{{CompatChrome(45.0)}} [1]</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> + +<table> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatNo() }}</td> + <td> + <p>{{CompatChrome(44.0)}} [1]</p> + </td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td> + <p>{{CompatChrome(44.0)}} [1]</p> + </td> + </tr> + <tr> + <td><code>prompt()</code> method.</td> + <td>{{ CompatNo() }}</td> + <td>{{CompatChrome(45.0)}} [1]</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{CompatChrome(45.0)}} [1]</td> + </tr> + </tbody> +</table> + +<p>[1] <font face="Consolas, Liberation Mono, Courier, monospace">B</font>ehind the flag<em>chrome://flags/#bypass-app-banner-engagement-checks</em></p> |