关闭WiFi时navigator.onLine仍为true,设置为“离线工作”时为false在浏览器中 [英] navigator.onLine still true when turning off WiFi, false when set "work offline" in browser

查看:527
本文介绍了关闭WiFi时navigator.onLine仍为true,设置为“离线工作”时为false在浏览器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

navigator.onLine仍然返回true。这是违反直觉的行为。但是当我在像Firefox这样的浏览器中设置脱机工作时,它会正确返回false。这是预期的吗?

navigator.onLine is still returning true when I turn off Wi-Fi (Airport on my notebook in OS X). This is counterintuitive behavior. But when I set "work offline" in a browser like Firefox, it correctly returns false. Is this expected?

alert(navigator.onLine ? "online" : "offline");


推荐答案

是的。浏览器不向页面提供网络连接信息,而是使用Work Offline的状态作为值。

Yes. The browser doesn't provide network connectivity information to the page, but rather uses Work Offline's status as the value.

这篇关于关闭WiFi时navigator.onLine仍为true,设置为“离线工作”时为false在浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆