MENU
URL & Network Information
The URL interface allows you to parse and encode URL strings.
RESETRUNFULL
RESETRUNFULL
<!doctype html><html>
<body>
<p></p>
<script>
var u = new URL("https://my-site.com:8080/products/watch?id=abc123&name=G%20Shock#main%20section");
console.log(
u.protocol, // https:
u.hostname, // my-site.com
u.port, // 8080
u.pathname, // /products/watch
u.searchParams.get('name'), // G Shock
u.hash); // main%20section;
u = new URL("../cats", "http://www.example.com/dogs");
console.log(u.toString()); // http://www.example.com/cats
u.href = "http://www.example.com/fish";
u.port = 8000;
document.querySelector("p").innerHTML = u.origin; // http://www.example.com:8000
</script></body></html>
The NetworkInformation interface describes information about the client's network.
RESETRUNFULL
RESETRUNFULL
<!doctype html><html>
<body>
<script>
var c = navigator.connection;
c.addEventListener('change',()=>{ // eg. when the Wifi is disconnected
console.log(c);
});
/*NetworkInformation {
onchange: null,
effectiveType: "4g",
rtt: 100, // round-trip time in milliseconds
downlink: 8.5, // effective bandwidth in kbps
saveData: false // reduced data usage?
}*/
</script></body></html>