aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/client/index.html
blob: 33231d6ddfc4597d8174a9b6fcf94701022f6239 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
title: Client
slug: Web/API/Client
tags:
  - API
  - Client
  - Experimental
  - Interface
  - NeedsTranslation
  - Reference
  - Service Workers
  - ServiceWorkerClient
  - ServiceWorkers
  - TopicStub
translation_of: Web/API/Client
---
<p>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</p>

<p><code>Client</code> 接口表示一个可执行的上下文,如{{domxref("Worker")}}{{domxref("SharedWorker")}}{{domxref("Window")}} 客户端由更具体的{{domxref("WindowClient")}}表示。 你可以从{{domxref("Clients.matchAll","Clients.matchAll()")}} 和{{domxref("Clients.get","Clients.get()")}}等方法获取<code>Client</code>/<code>WindowClient</code>对象。</p>

<h2 id="Methods">Methods</h2>

<dl>
 <dt>{{domxref("Client.postMessage()")}}</dt>
 <dd>向client发送一条消息。</dd>
</dl>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{domxref("Client.id")}} {{readonlyInline}}</dt>
 <dd>客户端的唯一通用标识符,字符串形式。</dd>
 <dt>{{domxref("Client.type")}} {{readonlyInline}}</dt>
 <dd>客户端的类型,字符串形式。可能是"<code>window"</code>, "<code>worker"</code>, 或 "<code>sharedworker"。</code></dd>
 <dt>{{domxref("Client.url")}} {{readonlyInline}}</dt>
 <dd>客户端的URL,字符串形式。</dd>
</dl>

<h2 id="规范">规范</h2>

<table>
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Service Workers', '#client', 'Client')}}</td>
   <td>{{Spec2('Service Workers')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<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 (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(40)}}</td>
   <td>{{ CompatGeckoDesktop("44.0") }}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatOpera(27)}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>type</code> property</td>
   <td>{{CompatChrome(60)}}</td>
   <td>{{ CompatGeckoDesktop("54.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera(47)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>

<table>
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(40)}}</td>
   <td>{{CompatChrome(40)}}</td>
   <td>{{ CompatGeckoMobile("44.0") }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatOperaMobile(27)}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>type</code> property</td>
   <td>{{CompatChrome(60)}}</td>
   <td>{{CompatChrome(60)}}</td>
   <td>{{ CompatGeckoMobile("54.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOperaMobile(47)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>

<ul>
 <li>[1] Service workers (and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Push_API">Push</a>) have been disabled in the <a href="https://www.mozilla.org/en-US/firefox/organizations/">Firefox 45 &amp; 52 Extended Support Releases</a> (ESR.)</li>
</ul>

<h2 id="See_also">See also</h2>

<ul>
 <li>使用<a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Service Workers</a></li>
 <li><a href="https://jakearchibald.github.io/isserviceworkerready/">ServiceWorker准备好了么?</a></li>
 <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a></li>
</ul>