var online = navigator.onLine; not working every time. Sometimes your connection is turned on, but you cannot retrieve data from the Internet or not access the site, even if you are online ... so the online return time is true because you are online. At that time, "navigator.onLine" is not usable.
βYou can receive false positives, for example, when virtualization software with virtual Ethernet adapters that are alwaysβ connected βis running on the computer. Therefore, if you really want to determine the online status of the browser, you must develop additional tools for checks. To learn more, see the HTML5 Rocks Article, " check this article
you should use ajax request to check ....
source share