Web/API/EventSource/close

From Get docs


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 StandardThe definition of 'close()' in that specification. Living Standard Initial definition


Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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


See also