close
event is fired when a connection with a
WebSocket
is closed.
| 冒泡 | No |
|---|---|
| 可取消 | No |
| 接口 |
CloseEvent
|
| 事件处理程序特性 |
onclose
|
You might want to know when the connection has been closed so that you can update the UI or, perhaps, save data about the closed connection. Given that you have a variable called
exampleSocket
that refers to an opened
WebSocket
, this handler would handle the situation where the socket has been closed.
exampleSocket.addEventListener('close', (event) => {
console.log('The connection has been closed successfully.');
)};
You can perform the same actions using the event handler property, like this:
exampleSocket.onclose = function (event) {
console.log('The connection has been closed successfully.');
};
| 规范 | 状态 |
|---|---|
|
HTML 实时标准
The definition of 'WebSocket close' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
close
event
|
Chrome Yes | Edge 12 | Firefox Yes | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android ? | Safari iOS ? | Samsung Internet Android Yes |
完整支持
兼容性未知
WebSocket