The window.navigator object provides information about the visitor's browser. It acts like a "detective" that can tell you which web browser is being used, which platform (OS) it is running on, and even whether the user is currently connected to the internet.
Here is what your browser tells JavaScript about itself right now:
The cookieEnabled property returns true if cookies are enabled in the visitor's browser, and false otherwise.
if (navigator.cookieEnabled) {
console.log("Cookies are allowed!");
} else {
console.log("Cookies are disabled.");
}
The platform property returns the platform (operating system engine) for which the browser was compiled.
// Example outputs: "Win32", "MacIntel", "Linux x86_64"
console.log(navigator.platform);
The userAgent property returns the user-agent header sent by the browser to the server. It contains deep details about the browser name, version, and the engine.
console.log(navigator.userAgent);
The onLine property returns a boolean value stating whether the browser is working online or offline.
if (navigator.onLine) {
alert("You are online!");
} else {
alert("You are currently offline.");
}
| Property | Description |
|---|---|
navigator.cookieEnabled |
Returns true if cookies are enabled |
navigator.userAgent |
Returns the user-agent string |
navigator.language |
Returns the browser's language setting |
navigator.onLine |
Returns true if the browser is online |
navigator.platform |
Returns the system platform (e.g., Win32) |
navigator.javaEnabled() |
Returns true if Java is enabled (Method) |
onLine property helps detect connection drops.appName are now "deprecated" and usually return "Netscape" for compatibility.