JS Navigator
window.navigator describes the browser, OS, and a growing list of device capabilities. Useful pieces are the connection info, languages, and feature-detection helpers.
Practical properties
| Property | What it returns |
|---|---|
navigator.language | Preferred language tag, e.g. "en-US". |
navigator.languages | Ordered list of preferred languages. |
navigator.onLine | Boolean — false means definitely offline. |
navigator.cookieEnabled | Are cookies enabled? |
navigator.userAgent | UA string — historically unreliable. Use feature detection instead. |
navigator.userAgentData | Modern UA Client Hints (Chromium). |
navigator.hardwareConcurrency | Logical CPU cores. |
navigator.deviceMemory | Approximate RAM in GB. |
Useful sub-APIs
| API | Purpose |
|---|---|
navigator.clipboard | Read / write the clipboard. |
navigator.geolocation | Get the user's coordinates (with consent). |
navigator.serviceWorker | Register service workers (PWA, offline). |
navigator.mediaDevices | Camera, mic, screen-share. |
navigator.share({ url, title }) | Native share sheet (mostly mobile). |
navigator.connection | Network speed/type (Chromium). |
Online/offline events
JS
window.addEventListener("online", () => statusBar.textContent = "✓ online");
window.addEventListener("offline", () => statusBar.textContent = "⚠ offline");
Note:
navigator.onLine only knows about the OS network state — it can't tell whether your specific server is reachable. Confirm with a fetch.Tip: Don't parse the UA string to make UI decisions. Use feature detection (
"clipboard" in navigator, typeof IntersectionObserver !== "undefined") — it survives browser changes.Example
Example
<!DOCTYPE html>
<html>
<body>
<p id="out"></p>
<script>
document.getElementById("out").textContent = "Hello from JS Navigator!";
</script>
</body>
</html>
Try it Yourself »
Exercise
Show the user's preferred language tag.
console.log(navigator.
);
Eight letters.
Discussion
Loading…