Javascript Browser Navigator onLine Property

Introduction

Find out whether the browser is online:

var x = "Is the browser online? " + navigator.onLine;

Click the button to see if the browser is online.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/* ww w  . java  2s . c  o m*/
  var x = "Is the browser online? " + navigator.onLine;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The onLine property returns a Boolean value that specifies whether the browser is in online or offline mode.

This property is read-only.

The onLine property returns a Boolean indicating whether the browser is in online or offline mode. Returns true if the browser is online, otherwise it returns false.




PreviousNext

Related