aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/clients/get/index.html
blob: 3a9d732f63b513ea47ce9ed9868039a35b5214e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: Clients.get()
slug: Web/API/Clients/get
translation_of: Web/API/Clients/get
---
<div>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</div>

<p>{{domxref("Clients")}} 接口的 <code><strong>get</strong></code><strong><code>()</code></strong> 方法 获取给定 <code>id</code> 匹配的Service Worker client,并在 {{jsxref("Promise")}} 中返回它.</p>

<h2 id="语法">语法</h2>

<pre class="brush: js">self.clients.get(id).then(function(client) {
  // do something with your returned client
});</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>id</code></dt>
 <dd>一个 {{domxref("DOMString")}} ,表示您想要获取的 client id.</dd>
</dl>

<h3 id="返回">返回</h3>

<dl>
 <dd>一个resolve为 {{domxref("Client")}} 对象的 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" title="The Promise object is used for deferred and asynchronous computations. A Promise is in one of the three states:">Promise</a></code> .</dd>
</dl>

<h2 id="示例">示例</h2>

<pre class="brush: js">self.clients.get(options).then(function(client) {
  self.clients.openWindow(client.url);
});</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-get-method', 'get()')}}</td>
   <td>{{Spec2('Service Workers')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div>


<p>{{Compat("api.Clients.get")}}</p>
</div>

<p> </p>