Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to check if connected to internet js

function getStatus() {
    const statusDisplay = document.getElementById("status");
    statusDisplay.textContent = navigator.onLine ? "Online" : "OFFline";
    if (statusDisplay.textContent === "Online") {
      console.log('Online');
    } else if (statusDisplay.textContent === "OFFline"){
      console.log('Offline');
    }
}
setInterval(getStatus, 2000);
 
PREVIOUS NEXT
Tagged: #check #connected #internet #js
ADD COMMENT
Topic
Name
1+3 =