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 2020년 1월.
참고 : 이 기능은 Web Worker에서 사용할 수 있습니다.
EventSource
인터페이스의 close()
메서드는
연결이 되어 있는 경우 연결을 닫고 EventSource.readyState
속성을 2
(닫힘)으로 설정합니다.
참고 : 연결이 이미 닫혀 있는 경우, 메서드는 아무 동작도 수행하지 않습니다.
구문
js
close()
매개변수
없음.
반환 값
없음 (undefined
).
예제
js
const button = document.querySelector("button");
const evtSource = new EventSource("sse.php");
button.onclick = () => {
console.log("Connection closed");
evtSource.close();
};
참고 : GitHub에서 전체 예시를 확인할 수 있습니다. PHP를 사용한 간단한 SSE 데모를 참고하세요.
명세서
Specification |
---|
HTML> # dom-eventsource-close-dev> |
브라우저 호환성
Loading…