EventSource.close()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

La fonction close() de l'interface EventSource coupe la connection, si existante, et affecte à la variable EventSource.readyState la valeur 2 (closed).

Note : Si la connexion est déjà fermé, la fonction n'agit pas.

Syntaxe

js
eventSource.close();

Paramètres

Aucun.

Valeur de retour

Nulle.

Exemples

js
var bouton = document.querySelector("button");
var evtSource = new EventSource("sse.php");

bouton.onclick = function () {
  console.log("Connection fermée");
  evtSource.close();
};

Note : Vous pouvez trouver un exemple complet sur GitHub — voir Demo simple de SSE utilisant PHP.

Spécifications

Specification
HTML
# dom-eventsource-close-dev

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
close

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi