WebSocket.readyState

概要

返回当前 WebSocket 的链接状态,只读。

语法

var readyState = aWebSocket.readyState;

以下其中之一

0 (WebSocket.CONNECTING)
正在链接中
1 (WebSocket.OPEN)
已经链接并且可以通讯
2 (WebSocket.CLOSING)
连接正在关闭
3 (WebSocket.CLOSED)
连接已关闭或者没有链接成功

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'WebSocket.readyState' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
readyStateChrome Full support 43Edge Full support 12Firefox Full support 19IE Full support 10Opera Full support 30Safari Full support 10WebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 19Opera Android Full support 30Safari iOS Full support 10Samsung Internet Android Full support 4.0

Legend

Full support  
Full support