CloseEvent: CloseEvent() コンストラクター

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

CloseEvent() コンストラクターは新しい CloseEvent オブジェクトを生成します。

構文

js
new CloseEvent(type)
new CloseEvent(type, options)

type

このイベントの名前を示す文字列です。 大文字小文字を区別し、ブラウザーは常に close を設定します。

options 省略可

オブジェクトで、Event() で定義されているものに加え、次のプロパティを持ちます。

wasClean 省略可

論理値で、接続がきれいに閉じたかどうかを示します。既定値は false です。

code 省略可

整数で、サーバーから送られる接続クローズコードを表します。既定値は 0 です。

reason 省略可

文字列で、サーバーが接続を閉じる理由を人間が理解できる形で表したものです。既定値は '' です。

返値

新しい CloseEvent オブジェクトです。

仕様書

Specification
WebSockets Standard
# dom-closeevent-closeevent

ブラウザーの互換性

BCD tables only load in the browser

関連情報

  • CloseEvent: 作成するオブジェクトのインターフェイス。