MDN self-hosted library · e01.org

EventSource: open event

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const evtSource = new EventSource("sse.php");

// addEventListener version
evtSource.addEventListener("open", (e) => {
  console.log("The connection has been established.");
});

// onopen version (but note that this replaces other event listeners
// added using onopen, if any)
evtSource.onopen = (e) => {
  console.log("The connection has been established.");
};