From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/websocket/close/index.html | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 files/zh-cn/web/api/websocket/close/index.html (limited to 'files/zh-cn/web/api/websocket/close') diff --git a/files/zh-cn/web/api/websocket/close/index.html b/files/zh-cn/web/api/websocket/close/index.html new file mode 100644 index 0000000000..046dd5c079 --- /dev/null +++ b/files/zh-cn/web/api/websocket/close/index.html @@ -0,0 +1,58 @@ +--- +title: WebSocket.close() +slug: Web/API/WebSocket/close +translation_of: Web/API/WebSocket/close +--- +

{{APIRef("Web Sockets API")}}

+ +

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

+ +

语法

+ +
WebSocket.close();
+ +

参数

+ +
+
code {{optional_inline}}
+
一个数字状态码,它解释了连接关闭的原因。如果没有传这个参数,默认使用1005。{{domxref("CloseEvent")}}的允许的状态码见状态码列表
+
reason {{optional_inline}}
+
一个人类可读的字符串,它解释了连接关闭的原因。这个UTF-8编码的字符串不能超过123个字节。
+
+ +

抛出的异常

+ +
+
INVALID_ACCESS_ERR
+
一个无效的code
+
SYNTAX_ERR
+
reason 字符串太长(超过123字节)
+
+ +
+

注意: 在Gecko 8.0 {{geckoRelease("8.0")}}之前版本的Gecko里,这个方法不支持传参数。

+
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
HTML Living Standard
+ The definition of 'WebSocket.close()' in that specification.
Living StandardInitial definition
+ +

Browser compatibility

+ + + +

{{Compat("api.WebSocket.close")}}

-- cgit v1.2.3-54-g00ecf