I have written the script to check the network connection but it not working.
<script type="text/javascript">
app.initialize();
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 Internet';
return states[networkState];
}
var result=checkConnection();
if(result=="No Internet")
{
alert("Status: "+states[networkState]);
}
else
{
alert("Have Internet");
}
</script>
here in the body tag i call the onload="checkConnection()" and it return the value to var result = checkConnection();