Skip to content

Instantly share code, notes, and snippets.

@gitdagray
Created July 29, 2020 20:05
Show Gist options
  • Save gitdagray/26c7f1d828fbc8659e8624500a9af07d to your computer and use it in GitHub Desktop.
Save gitdagray/26c7f1d828fbc8659e8624500a9af07d to your computer and use it in GitHub Desktop.
navigator.onLine with offline and online event listeners
window.addEventListener("load", (event) => {
const statusDisplay = document.getElementById("status");
statusDisplay.textContent = navigator.onLine ? "Online" : "Offline";
});
window.addEventListener("offline", (event) => {
const statusDisplay = document.getElementById("status");
statusDisplay.textContent = "OFFline";
});
window.addEventListener("online", (event) => {
const statusDisplay = document.getElementById("status");
statusDisplay.textContent = "Online";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment