WebSocket.close() - Web APIs 编辑
The WebSocket.close()
method closes the WebSocket
connection or connection attempt, if any. If the connection is already CLOSED
, this method does nothing.
Syntax
WebSocket.close();
Parameters
code
Optional- A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1005 is assumed. See the list of status codes of
CloseEvent
for permitted values. reason
Optional- A human-readable string explaining why the connection is closing. This string must be no longer than 123 bytes of UTF-8 text (not characters).
Exceptions thrown
INVALID_ACCESS_ERR
- An invalid
code
was specified. SYNTAX_ERR
- The
reason
string is too long or contains unpaired surrogates.
Note: In Gecko, this method didn't support any parameters prior to Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5).
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'WebSocket.close()' in that specification. | Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论