How to check device is Online or Offline Phonegap

cordova, javascript, jquery, offline

Solution

You can use `navigator.onLine`:

var isOffline = 'onLine' in navigator && !navigator.onLine;

if ( isOffline ) {
    //local db
}
else {
    // internet data
}

But be aware of that if `navigator.onLine` isn't supported `isOffline` will always be false

Problem

What is the easiest way to check whether the device(smartphone) is online or offline. I'm working with phonegap, jquery mobile. I found this one. ``` document.addEventListener("online", yourCallbackFunction, false); ``` What I want to do is to check the Internet connection and decide about to get the data from the internet or from the device local database. ``` if(deviceoffline) getDataFromLokalDatabase(); else getDataFromInternet(); ```

Original source

Related problems