MDN self-hosted library · e01.org

Window: offline event

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

js
// addEventListener version
window.addEventListener("offline", (event) => {
  console.log("The network connection has been lost.");
});

// onoffline version (but note that this replaces other event listeners
// added using onoffline, if any)
window.onoffline = (event) => {
  console.log("The network connection has been lost.");
};