views:

126

answers:

1

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");
A: 

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

Delan Azabani
It seems odd because if I turn off Wi-Fi and cellular data by turning on airplane mode on an iPhone, and then return to that page without reloading, it returns true as offline (which is correct).
chimerical
Browsers may want to detect if network connectivity is down *and then* set the Work Offline variable to `false`. However, the user may always change this variable herself.
Delan Azabani