Reputation:
I am using online offline EventListener but its not working event.
I have place cordova.js
before code or after code its not working at all
document.addEventListener("offline", getSettinglocally, false);
document.addEventListener("online", getSettingremotly, false);
deviceReady
EventListener is working fine
Upvotes: 1
Views: 1916
Reputation: 6029
These events do not fire on load of the application. They are for catching these events after the application has completely loaded and is in use. If you want to capture the network state on load of the application use something like below:
initialConnection: function() {
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;
global.connectionStatus = states[networkState];
app.connectionStatus(global.connectionStatus);
if(global.connectionStatus) {
//do something when connected
}
else{
//do something else if not
}
}
And as noted in another answer for this you need the network-information plugin installed.
Upvotes: 1