This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

CloseEvent

Summary

Object representing the close event for a WebSocket.

Properties

code
The WebSocket connection close code provided by the server.
reason
Indicates the reason the server closed the WebSocket connection.
wasClean
Indicates whether the WebSocket connection was cleanly closed.

Methods

No methods.

Events

No events.

Examples



socket.onclose = function(event) {
  var code = event.code;
  var reason = event.reason;
  var wasClean = event.wasClean;
  // handle close event
};

Notes

When a WebSocket connection is closed, possibly cleanly, the user agent must create an event that uses the CloseEvent interface, with the event name close, which does not bubble, is not cancelable, has no default action, whose wasClean attribute is set to true if the connection closed cleanly and false otherwise, whose code attribute is set to the WebSocket connection close code, and whose reason attribute is set to the WebSocket connection close reason; and then queue a task to first change the readyState attribute’s value to CLOSED (3), and then dispatch the event at the WebSocket object.

Related specifications

W3C WebSocket Specification
W3C Candidate Recommendation

Attributions