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. optionsOptional-
An object that, in addition of the properties defined in
Event(), has the following properties:wasCleanOptional-
A boolean value indicating if the connection has been closed cleanly or not. It defaults to
false. codeOptional-
An integer representing the connection close code sent by the server. It defaults to
0. reasonOptional-
A string containing a human-readable reason describing why the server closed the connection. It defaults to
''
Return value
A new CloseEvent object.
Specifications
| Specification |
|---|
| WebSockets Standard # dom-closeevent-closeevent |
Browser compatibility
BCD tables only load in the browser
See also
CloseEvent, the interface of the objects it constructs.