W3cubDocs

/Web APIs

CloseEvent: CloseEvent() constructor

The CloseEvent() constructor creates a new CloseEvent object.

Syntax

js

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

Parameters

type

A string with the name of the event. It is case-sensitive and browsers always set it to close.

options Optional

An object that, in addition of the properties defined in Event(), has the following properties:

wasClean Optional

A boolean value indicating if the connection has been closed cleanly or not. It defaults to false.

code Optional

An integer representing the connection close code sent by the server. It defaults to 0.

reason Optional

A string containing a human-readable reason describing why the server closed the connection. It defaults to ''

Return value

A new CloseEvent object.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
CloseEvent 16 14 11 No 12.1 6 4.4 18 14 12.1 6 1.0

See also

  • CloseEvent, the interface of the objects it constructs.

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/CloseEvent