javascript
First written: Aug-2023
last changed Nov-2023

To test (using javascript) to if the browser is on a wifi connection then use the following code

js
const networkInformation = navigator.connection;

if (networkInformation.type === "cellular") {
  console.log("The internet is connected via cell data.");
} else if (networkInformation.type === "wifi") {
  console.log("The internet is connected via WiFi.");
} else {
  console.log("The internet is not connected to a WiFi or cellular network (i.e. it may be connected to a network via wire).");
}


link Click to view a demo

square