We have many customers in remote areas and lost of connectivity is frequent. How can I detect if the javascript app is offline? Meaning cannot reach the server and load the templates.
2 Answers
I finally found a JSFiddle that does exactly that: Check if the web application is online. It uses window.navigator.onLine.
JSFiddle: http://jsfiddle.net/rommsen/QY8w2/
Source: https://groups.google.com/d/msg/angular/ZncvSVUc9y4/S4jH1e_XgGoJ
5 Comments
joshschreuder
Note that
windows.navigator.onLine has different implementations depending on the browser, and a status of true only indicates connection to a LAN or router, not to a specific resource or the broader internet. You may need to specifically test connection to your desired resource and check for 404 to properly test offline conditions.Adam
You may want to check out Offline.js, an open-source library built for just this purpose.
Mawg
I didn't D/L it, I just opened up their simulator. rather than using their checkbox to pretend, I actually pulled my Ethernet cable. In Chrome & MS IE, I go the "you are offline" alert. FF did not show it. See also stackoverflow.com/questions/16242389/… which indicates that FF seems to be non-standard
Mawg
I just checked the Plunk in the awarded answer : works with Chrome Version 34.0.1847.137 m, MS IE v11.0.x.x, but NOT with FireFox v29.0.1
benek
This fiddle seems not working. Note that the rootScope cannot be injected in factory.