EventSource.close()
La fonction close()
de l'interface EventSource
coupe la connection, si existante, et affecte à la variable EventSource.readyState
(en-US) la valeur 2
(closed).
Note : Si la connexion est déjà fermé, la fonction n'agit pas.
Syntaxe
eventSource.close();
Paramètres
Aucun.
Valeur de retour
Nulle.
Exemples
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 | Status | Comment |
---|---|---|
HTML Living Standard La définition de 'close()' dans cette spécification. |
Standard évolutif | Initial definition |
Compatibilité des navigateurs
BCD tables only load in the browser