我正在使用下面的这个函数来获取互联网连接类型
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]);
}
这会提醒状态: alert('Connection type: ' + states[networkState]);
我需要做的是只有在状态为 states[Connection.NONE] 时才会发出警报
我试过:
if ((states[networkState]) = states[Connection.NONE]) {
alert('No internet connection here');
}
但这没有用。