I tested navigator.online and it worked until I built the app with PhoneGap, after that, navigator.online always returned true. Does anybody know how can I un-cache or refresh this value? I need it on "on click" events.
Asked
Active
Viewed 2,585 times
2
-
1Yeah it is broken in the WebView component that PhoneGap uses but works fine in the Browser. It looks like we may be able to fix it for 2.2 though. In the meantime use what @Rishi has posted. – Simon MacDonald Sep 18 '12 at 13:52
-
1Can anyone confirm if this is now fixed in the latest (currently 2.7.0 ) version of Phonegap? – Ben Clayton May 22 '13 at 18:34
1 Answers
5
I was also facing this issue while I was developing an application.
What I used is:
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
These events will be fired when the device is disconnected or connected to internet on the fly.
You can store some global variables in the function
function onOnline(){}
and
function onOffline(){}
Than check the values of those global variables and do whatever you want to according to the value.

Rishi
- 330
- 2
- 13