I am using this function below to get the internet connection type
function checkConnection() {
var networkState = navigator.network.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.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
This alerts the state: alert(‘Connection type: ‘ + states[networkState]);
What I need to do it get it to alert only if the state is states[Connection.NONE]
I tried:
if ((states[networkState]) = states[Connection.NONE]) {
alert('No internet connection here');
}
but that didn’t work.
Logically, this
Should be