IDENTIFY WHETHER THE BROWSER IS ONLINE

There are two ways to detect whether a browser is online or offline in JavaScript. The first is to query the navigator.onLine property, if supported, to give the current state of the network connection media. So if the Ethernet cable is unplugged or the Wi-Fi connection is lost, this property is updated. The second way is to listen to the online and offline browser events, if supported, to notify you when the navigator.onLine property changes.

This is true in most browsers and operating systems, but there are some notable exceptions:

  • Internet Explorer 9 does provide the navigator.onLine property, but it will not post online and offline events when it changes.
  • Firefox 5 and Opera 11.50 do provide navigator.onLine ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.