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/ja/web/api/websocket/close_event/index.html | 80 +++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 files/ja/web/api/websocket/close_event/index.html (limited to 'files/ja/web/api/websocket/close_event') diff --git a/files/ja/web/api/websocket/close_event/index.html b/files/ja/web/api/websocket/close_event/index.html new file mode 100644 index 0000000000..136ceea555 --- /dev/null +++ b/files/ja/web/api/websocket/close_event/index.html @@ -0,0 +1,80 @@ +--- +title: 'WebSocket: close イベント' +slug: Web/API/WebSocket/close_event +tags: + - Reference + - Web + - WebSocket + - close + - events + - イベント +translation_of: Web/API/WebSocket/close_event +--- +
{{APIRef}}
+ +

close イベントは、 WebSocket のコネクションが閉じられたときに発生します。

+ + + + + + + + + + + + + + + + + + + + +
バブリングなし
キャンセル不可
インターフェイス{{domxref("Event")}}
イベントハンドラープロパティ{{ domxref("WebSocket.onclose","onclose")}}
+ +

+ +

コネクションが閉じられる時が分かれば、 UI を更新させたり、閉じたコネクションについてのデータを保存したりすることができます。以下の例では exampleSocket と呼ばれる変数が開かれた WebSocket を参照しており、このハンドラーが、ソケットが閉じられた場面を扱います。

+ +
exampleSocket.addEventListener('close', (event) => {
+  console.log('The connection has been closed successfully.');
+)};
+ +

同じことを、イベントハンドラープロパティを用いて行うこともできます。

+ +
exampleSocket.onclose = function (event) {
+  console.log('The connection has been closed successfully.');
+};
+ +

仕様書

+ + + + + + + + + + + + + + +
仕様書状態
{{SpecName("HTML WHATWG", "web-sockets.html#event-close", "WebSocket close")}}{{Spec2("HTML WHATWG")}}
+ +

ブラウザーの互換性

+ +

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

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf