WebSocket:readyState 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

备注: 此特性在 Web Worker 中可用。

WebSocket.readyState 只读属性返回 WebSocket 连接的当前状态。

一个数字,是 WebSocket 接口定义的四个可能状态常量之一:

WebSocket.CONNECTING(0)

套接字已创建,但连接尚未打开。

WebSocket.OPEN(1)

连接已打开,准备进行通信。

WebSocket.CLOSING(2)

连接正在关闭中。

WebSocket.CLOSED(3)

连接已关闭或无法打开。

规范

Specification
WebSockets
# ref-for-dom-websocket-readystate①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
readyState

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support