我有以下代码。如果我启动wifi功能关闭(在我的选项卡上),我收到了警报。到现在为止还挺好。但是,如果我打开wifi然后,我仍然得到警报,我没有连接。
有什么想法吗?
//Kontrolle, ob benötigtes Netzwerk vorhanden ist
function checkNetwork()
{
network()
if (networkState != 'none')
{
networkState = '';
writeDataToFile();
}
else
{
alert('Bitte die Internetverbindung checken');
networkState = '';
checkNetwork()
}
}
//Welches Netzwerk ist gerade vorhanden
function network()
{
networkState = navigator.connection.type;
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]);
}