How to detect online/offline event cross-browser?

Currently in 2011, the various browser vendors cannot agree on how to define offline. Some browsers have a Work Offline feature, which they consider separate to a lack of network access, which again is different to internet access. The whole thing is a mess. Some browser vendors update the navigator.onLine flag when actual network access is lost, others don’t.

From the spec:

Returns false if the user agent is
definitely offline (disconnected from
the network). Returns true if the user
agent might be online.

The events online and offline are
fired when the value of this attribute
changes.

The navigator.onLine attribute must
return false if the user agent will
not contact the network when the user
follows links or when a script
requests a remote page (or knows that
such an attempt would fail), and must
return true otherwise.

Finally, the spec notes:

This attribute is inherently
unreliable. A computer can be
connected to a network without having
Internet access.

Leave a Comment