aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/websocket/onclose/index.html
blob: 0ed1b7ffe19ce581238e10c939a780245a8e17d5 (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
---
title: WebSocket.onclose
slug: Web/API/WebSocket/onclose
translation_of: Web/API/WebSocket/onclose
---
<p>{{APIRef("Web Sockets API")}}</p>

<p><strong><code>WebSocket.onclose</code></strong> 属性返回一个事件监听器,这个事件监听器将在 WebSocket 连接的{{domxref("WebSocket.readyState","readyState")}} 变为 <code>CLOSED</code>时被调用,它接收一个名字为“close”的 {{domxref("CloseEvent")}} 事件。</p>

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

<pre class="syntaxbox"><em>WebSocket</em>.onclose = function(event) {
  console.log("WebSocket is closed now.");
};</pre>

<h2 id="值"></h2>

<p>一个{{domxref("EventListener")}}.</p>

<h2 id="文档">文档</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', '#handler-websocket-onclose', 'WebSocket: onclose')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>