js獲取前端網路狀態
阿新 • • 發佈:2019-02-03
function lineBoth(){
if(navigator.onLine){
console.log("連結到網路")
document.getElementById("noNet").style.display='none'
}else{
console.log("當前網路無連結")
document.getElementById("noNet").style.display='block'
document.getElementById("cardFull").style.display='none'
document.getElementById("noCard").style.display='none'
}
}
window.setInterval("lineBoth()",100);
if(navigator.onLine){
console.log("連結到網路")
document.getElementById("noNet").style.display='none'
}else{
console.log("當前網路無連結")
document.getElementById("noNet").style.display='block'
document.getElementById("cardFull").style.display='none'
document.getElementById("noCard").style.display='none'
}
}
window.setInterval("lineBoth()",100);