The CloseEvent() constructor creates a new CloseEvent.


 event = new CloseEvent(typeArg, closeEventInit);


Is a DOMString representing the name of the event.
Is a CloseEventInit dictionary, having the following fields:
  • "wasClean", optional and defaulting to false, of type long, indicates if the connection has been closed cleanly or not.
  • "code", optional and defaulting to 0, of type unsigned short, that is the connection close code sent by the server.
  • "reason", optional and defaulting to '', of type DOMString,  that is a human-readable reason why the server closed the connection.

The CloseEventInit dictionary also accepts fields from the EventInit dictionary.


Specification Status Comment
HTML Living Standard
The definition of 'CloseEvent()' in that specification.
Living Standard Initial definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 8 (8) ? ? ?
Support in Web workers ? (Yes) ? ? ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? 8.0 (8) ? ? ?
Support in Web workers ? ? (Yes) ? ? ?

See also

  • CloseEvent, the interface of the objects it constructs.

Document Tags and Contributors

Contributors to this page: teoli
Last updated by: teoli,