aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/clients/claim
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/clients/claim
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/clients/claim')
-rw-r--r--files/zh-cn/web/api/clients/claim/index.html66
1 files changed, 66 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/clients/claim/index.html b/files/zh-cn/web/api/clients/claim/index.html
new file mode 100644
index 0000000000..4797f8c064
--- /dev/null
+++ b/files/zh-cn/web/api/clients/claim/index.html
@@ -0,0 +1,66 @@
+---
+title: Clients.claim()
+slug: Web/API/Clients/claim
+translation_of: Web/API/Clients/claim
+---
+<p>{{SeeCompatTable}}{{APIRef("Service Worker Clients")}}</p>
+
+<p><span class="seoSummary">{{domxref("Clients")}} 接口的  <strong><code>claim()</code></strong> 方法允许一个激活的 service worker 将自己设置为其 {{domxref("ServiceWorkerRegistration.scope", "scope")}} 内所有</span>clients 的<span class="seoSummary">{{domxref("ServiceWorkerContainer.controller", "controller")}} . 这会在由此service worker 控制的任何 clients 中触发 {{domxref("ServiceWorkerContainer","navigator.serviceWorker")}}  上的  "<code>controllerchange</code>"  事件.</span></p>
+
+<p>当一个 service worker 被初始注册时,页面在下次加载之前不会使用它。 <code>claim()</code> 方法会立即控制这些页面。请注意,这会导致 service worker 控制通过网络定期加载的页面,或者可能通过不同的 service worker 加载.</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">await clients.claim();
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<p>None.</p>
+
+<h3 id="返回">返回</h3>
+
+<p>A {{jsxref("Promise")}} for <code>void</code>.</p>
+
+<h2 id="示例">示例</h2>
+
+<p>The following example uses <code>claim()</code> inside service worker's "<code>activate</code>" event listener so that clients loaded in the same scope do not need to be reloaded before their fetches will go through this service worker.</p>
+
+<pre class="brush: js">self.addEventListener('activate', event =&gt; {
+  event.waitUntil(clients.claim());
+});</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Service Workers', '#clients-claim', 'claim()')}}</td>
+ <td>{{Spec2('Service Workers')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("api.Clients.claim")}}</p>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Using Service Workers</a></li>
+ <li><a href="https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/lifecycle">The service worker lifecycle</a></li>
+ <li><a href="https://jakearchibald.github.io/isserviceworkerready/">Is ServiceWorker ready?</a></li>
+ <li>{{jsxref("Promise", "Promises")}}</li>
+ <li>{{domxref("ServiceWorkerGlobalScope.skipWaiting()", "self.skipWaiting()")}} - skip the service worker's waiting phase </li>
+</ul>