Navigator.onLine does not work on my mobile phone. How to check online online.fffline ??? In Phonegap

I am using phonegap for my application. My application is based on RSS_FEED from one website. but my requirement is when the internet is not there, the application should alert- offline.

when the application launches on the Internet all the data stored in the database. and when the Internet does not have time data obtained from the database, so my problem is only that the application shows me online every time I use it navigator.onLine.

if(navigator.onLine) {
    alert("check online");
    loadScript("http://www.google.com/jsapi",msgOnFn)
    loadScript("js/googleapi.js", msgOnFn);
} else {
    loadScript("js/db.js",msgOffFn);
}

I tried THIS ALSO In this case, none or wifi is displayed every time . I do not understand why this is happening.

in a web browser, it works fine. :)

+4
1

, .

, true false:

function checkConnection() {
    var networkState = navigator.connection.type;

    var states = {};
    states[Connection.UNKNOWN]  = false;
    states[Connection.ETHERNET] = true;
    states[Connection.WIFI]     = true;
    states[Connection.CELL_2G]  = true;
    states[Connection.CELL_3G]  = true;
    states[Connection.CELL_4G]  = true;
    states[Connection.CELL]     = true;
    states[Connection.NONE]     = false;
    if (states[networkState]) {
        return true;
    } else {
        return false;
    }
}
+4

Source: https://habr.com/ru/post/1532087/


All Articles