--- 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> {{Compat("api.Client")}} <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>