WebSocket.onmessage

The WebSocket.onmessage property is an event handler that is called when a message is received from the server. It is called with a MessageEvent.

Syntax

aWebSocket.onmessage = function(event) {
  console.debug("WebSocket message received:", event);
};

Value

An EventListener.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
onmessage
4
12
7
10
12.1
5
≤37
18
7
12.1
4.2
1.0

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/onmessage