blob: 27bcce6cf27ac80633715ad33da75049f681c780 (
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
|
---
title: WebSocket.onmessage
slug: Web/API/WebSocket/onmessage
tags:
- API
- Web API
- WebSocket
- 参考
- 属性
translation_of: Web/API/WebSocket/onmessage
---
<p>{{APIRef("Web Sockets API")}}</p>
<p><code><strong>WebSocket.onmessage</strong></code> 属性是一个当收到来自服务器的消息时被调用的 {{domxref("EventHandler")}}。它由一个{{domxref("MessageEvent")}}调用。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>aWebSocket</em>.onmessage = function(event) {
console.debug("WebSocket message received:", event);
};</pre>
<h2 id="值">值</h2>
<p>一个 {{domxref("EventListener")}}.</p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', '#handler-websocket-onmessage', 'WebSocket: onmessage')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>初始定义</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.WebSocket.onmessage")}}</p>
|