翻译不完整。 请帮助我们翻译这篇文章!

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"


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

An EventListener.


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

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onerrorChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes


Full support  
Full support
Compatibility unknown  
Compatibility unknown