代码示例:(标识:eg_js_navigator_online)
<!DOCTYPE html>
<html>
<body>

<h1>Navigator 对象</h1>

<p>如果浏览器在线,则 onLine 属性返回 true:</p>

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

<script>
document.getElementById("demo").innerHTML =
"navigator.onLine 是:" + navigator.onLine;
</script>

</body>
</html>
运行结果: