This is because if you turn WIFI off the type
porperty of navigator.network.connection
will not get initialised.
I would implement an extra check:
if (typeof navigator.connection !== "undefined")
Something like:
function checkConnection() {
if (typeof navigator.connection !== "undefined") {
if(navigator.network.connection.type == Connection.NONE || navigator.network.connection.type ==Connection.UNKNOWN){
return false;
}else{
return true;
}
} else {
return false;
}
}