The close()
method of the EventSource
interface closes the connection, if one is made, and sets the EventSource.readyState
attribute to 2
(closed).
Note: If the connection is already closed, the method does nothing.
Syntax
eventSource.close();
Parameters
None.
Return value
Void.
Examples
var button = document.querySelector('button'); var evtSource = new EventSource('sse.php'); button.onclick = function() { console.log('Connection closed'); evtSource.close(); }
Note: You can find a full example on GitHub — see Simple SSE demo using PHP.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'close()' in that specification. |
Living Standard | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
close | Chrome Full support 6 | Edge Full support 79 | Firefox Full support 6 | IE No support No | Opera Full support Yes | Safari Full support 5 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 45 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 |
Legend
- Full support
- Full support
- No support
- No support