The onLine
property tells whether the browser is in online or offline mode.
onLine |
Yes | Yes | Yes | Yes | Yes |
navigator.onLine
Type | Description |
---|---|
Boolean | tells whether the browser is in online or offline mode. |
The following code shows how to check whether the browser is online.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from w ww. j a v a2s . co m-->
<p id="demo"></p>
<script>
function myFunction() {
var x = "Is the browser online? " + navigator.onLine;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
A demonstration of all navigator properties.
<!DOCTYPE html>
<html>
<body>
<!--from ww w . ja v a 2 s. c om-->
<div id="demo"></div>
<script>
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Browser Language: " + navigator.language + "</p>";
txt+= "<p>Browser Online: " + navigator.onLine + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
The code above is rendered as follows: