当关闭WiFi时,navigator.onLine仍为true,在浏览器中设置为"脱机工作"时为false

chi*_*cal 6 javascript offlineapps

当我关闭Wi-Fi(OS X中我的笔记本上的机场)时,navigator.onLine仍然返回true.这是违反直觉的行为.但是当我在像Firefox这样的浏览器中设置"脱机工作"时,它会正确返回false.这是预期的吗?

alert(navigator.onLine ? "online" : "offline");
Run Code Online (Sandbox Code Playgroud)

Del*_*ani 4

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