WebSocket.onerror

The WebSocket.onerror property returns the event listener to be called when an error occurs. This is a simple event named "error".

WebSocket.onerror 属性中,你可以定义一个发生错误时执行的回调函数,此事件的事件名为"error"

语法

WebSocket.onerror = function(event) {
  console.error("WebSocket error observed:", event);
};

Specifications

Specification Status Comment
HTML Living Standard
WebSocket: onerror
Living Standard Initial definition

浏览器兼容性

No compatibility data found for api.WebSocket.onerror.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.