Navigator onLine属性用于返回一个布尔值,该值指定浏览器是处于联机还是脱机模式。这是一个只读属性,如果浏览器处于联机模式,则返回true;如果处于脱机模式,则返回false。
用法:
navigator.onLine
以下示例程序旨在说明Navigator onLine属性:
检查浏览器是处于在线还是离线模式。
Navigator onLine Property in HTML
h1 {
color:green;
}
h2 {
font-family:Impact;
}
body {
text-align:center;
}
GeeksforGeeks
Navigator onLine Property
For checking the browser's mode,
double click the "Check Mode" button:
Check Mode
function checkmode() {
// We use navigator.onLine to check if browser is online
var o =
"Is the browser in online mode? " + navigator.onLine;
document.getElementById("mode").innerHTML = o;
}
输出:
单击按钮后
支持的浏览器:导航器在线支持的浏览器如下:
谷歌浏览器
IE浏览器
Firefox
Opera
苹果Safari