Closes the WebSocket connection or connection attempt, if any.
- unsigned short
A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1000 (indicating a normal “transaction complete” closure) is assumed.
A human-readable string explaining why the connection is closing. This string must be no longer than 123 bytes of UTF-8 text (not characters).
No return value
The onclose event will return three attributes:
- wasClean (binary) - whether the connection closed cleanly.
- code (unsigned long) - code from the server.
- reason (text) - reason provided by the server.
If the code parameter is present but is not an integer equal to 1000 or in the range 3000 to 4999, this method throws an InvalidAccessError exception and aborts. If the reason parameter is longer than 123 bytes this method throws a SyntaxError exception, and aborts.
- W3C WebSocket Specification
- W3C Candidate Recommendation