WebSocket.close()

这篇翻译不完整。请帮忙从英语翻译这篇文章

WebSocket.close() 方法关闭 WebSocket  连接或连接尝试(如果有的话)。 如果连接已经关闭,则此方法不执行任何操作。

Syntax

WebSocket.close();

Parameters

code 可选
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 可选
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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge ? Firefox Full support 8
Full support 8
No support 4 — 8
Notes
Notes Parameters not supported, see bug 674716.
IE ? Opera Full support YesSafari ? WebView Android ? Chrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

文档标签和贡献者

此页面的贡献者: en20
最后编辑者: en20,