WebSocket: error event

翻译正在进行中。

当与websocket的连接已关闭时,将激发错误事件 (如下的数据无法发送).

Bubbles No
Cancelable No
Interface Event
Event handler property onerror

例子

// Create WebSocket connection
const socket = new WebSocket('ws://localhost:8080');

// Listen for possible errors
socket.addEventListener('error', function (event) {
  console.log('WebSocket error: ', event);
});

标准

Specification Status
HTML Living Standard
WebSocket error
Living Standard

浏览器兼容

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
error eventChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

查看更多