I\'m trying to get a pop-up to, well, pop up when there is no internet connection on the device.
I got the following example working, but now I want the alert only to sh
I'm just amalgamating a couple of answers here, but I wanted something which responded to the online/offline events but also knew at the start whether there was an internet connection. I was using this in an Angular controller which broadcast about state changes, but I've removed those parts for simplicity.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var _curStatus = false;
function toggleStatus(newVal) {
console.log('Setting internet connection state to: ' + newVal);
_curStatus = newVal;
// My angular $broadcast went here
}
var conType = navigator.network.connection.type;
toggleStatus((conType != Connection.NONE) && (conType != Connection.UNKNOWN));
document.addEventListener("online", function() {toggleStatus(true);}, false);
document.addEventListener("offline", function() {toggleStatus(false);}, false);
}
}