Navigator onLine 属性
Navigator 对象
定义和用法
onLine 属性是一个只读的布尔值,声明了系统是否处于脱机模式。
语法
navigator.onLine
浏览器支持
![]()
![]()
![]()
![]()
![]()
所有主要浏览器都支持 onLine 属性
实例
浏览器是否在线:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to see if the browser is online.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = navigator.onLine;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
Navigator 对象