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.

onclose

Summary

An event listener to be called when the WebSocket connection’s readyState changes to CLOSED. Receives a CloseEvent named "close".

Property of apis/websocket/WebSocketapis/websocket/WebSocket

Syntax

Note: This property is read-only.

var result = element.onclose;

Return Value

Returns an object of type

EventHandler

Examples

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

Related specifications

W3C WebSocket Specification
W3C Candidate Recommendation

Attributions