Window navigator.onLine
ตัวอย่าง
เบราว์เซอร์ออนไลน์หรือไม่
let online = navigator.onLine;
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
คุณสมบัติonLine
จะส่งคืน หากเบราว์เซอร์ออนไลน์ อยู่true
มิฉะนั้นfalse
คุณสมบัติonLine
เป็นแบบอ่านอย่างเดียว
บันทึก
คุณสมบัตินี้ไม่น่าเชื่อถือ
คอมพิวเตอร์สามารถเชื่อมต่อกับเครือข่ายโดยไม่ต้องเชื่อมต่ออินเทอร์เน็ต
ไวยากรณ์
navigator.onLine
คืนมูลค่า
พิมพ์ | คำอธิบาย |
บูลีน | true หากเบราว์เซอร์ออนไลน์อยู่ มิfalse ฉะนั้น |
ตัวอย่างเพิ่มเติม
แสดงคุณสมบัติของเนวิเกเตอร์ทั้งหมด:
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>";
รองรับเบราว์เซอร์
navigator.onLine
รองรับในทุกเบราว์เซอร์:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |