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.
实时标准

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: