📜  如何检查是否连接到互联网 js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:53.209000             🧑  作者: Mango

代码示例2
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);