This is a demo of the code:
/* celltest.js code to detect networkInformation and present a div showing the result */
/* See https://methodfish.com/Articles/iConnectionTest/docs for this code being run */
var result= "<div style='margin-top:10px; background-color:#dceadc;padding:10px;border-radius:9px'><i class='material-icons'>info</i> ";
if ( 1 ) {
const networkInformation = navigator.connection;
if (networkInformation.type === "cellular") {
result+="The internet is connected via cell data.";
}
else if (networkInformation.type === "wifi") {
result+="The internet is connected via WiFi.";
}
else {
result+="The internet is not connected to a WiFi or cellular network (i.e. it may be connected to a network via wire). ["+networkInformation.type+"]";
}
}
result+="</div>";
document.getElementById('result').innerHTML=result;