Cordova - apis . , , . , , , :
, true false , :
function checkConnection(){
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
if(states[networkState].indexOf("WiFi") != -1 || states[networkState].indexOf("Cell") != -1)
return true;
return false;
}
:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var connected = checkConnection();
if(connected){
}else{
}
}
online offline, :
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
}
function onOnline() {
}
function onOffline() {
}
network-information. .