Is the browser online?
let online = navigator.onLine;
Try it Yourself »
More "Try it Yourself" examples below.
The onLine
property returns true
if the browser is online, otherwise false
.
The onLine
property is read-only.
This property is unreliable.
A computer can be connected to a network without having Internet access.
navigator.onLine
Type | Description |
A boolean | true if the browser is in online, otherwise false . |
Display all navigator properties:
let text = "<p>Browser CodeName: " + navigator.appCodeName + "</p>" +
"<p>Browser Name: " + navigator.appName + "</p>" +
"<p>Browser Version: " + navigator.appVersion + "</p>" +
"<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>" +
"<p>Browser Language: " + navigator.language + "</p>" +
"<p>Browser Online: " + navigator.onLine + "</p>" +
"<p>Platform: " + navigator.platform + "</p>" +
"<p>User-agent header: " + navigator.userAgent + "</p>";
Try it Yourself »
navigator.onLine
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!