Navigator object in JavaScript
In this article, we will show you the properties of the navigator object in JavaScript.
The `window.navigator` object contains information about the visitor's browser. A Navigator object can be retrieved using the read-only `window.navigator` or `navigator` property.
Checkout more articles on JavaScript
- Set text direction based on input text language in JavaScript
- Methods of Promises in JavaScript
- Add days to a date in JavaScript
- Remove the first element from an array in JavaScript
- Animated sticky header on scroll using JavaScript
List of the navigator properties
- Browser platform
- Browser language
- Is the browser online
- Browser cookies
- Browser application name
- Browser application code name
- Browser version
- Browser agent
1. Browser platform
Use the `navigator.platform` to get the browser platform.
const platform = navigator.platform;
console.log(platform);
// Output: Win32
2. Browser language
The `navigator.language` returns the language.
const language = navigator.language;
console.log(language);
// Output: en-US
3. Is the browser online
Use the `navigator.onLine` to check if the browser is online or offline. It returns the boolean value.
const onLine = navigator.onLine;
console.log(onLine);
// Output: true
4. Browser cookies
The `navigator.cookieEnabled` returns true if the cookie is enabled otherwise false.
const cookieEnabled = navigator.cookieEnabled;
console.log(cookieEnabled);
// Output: true
5. Browser application name
Use the `navigator.appName` to get the browser application name. `Netscape` is the application name for IE11, Chrome, Firefox, and Safari.
const appName = navigator.appName;
console.log(appName);
// Output: Netscape
6. Browser application code name
Use the `navigator.appCodeName` to get the application code name. `Mozilla` is the application code name for Chrome, Firefox, IE, Safari, and Opera.
const appCodeName = navigator.appCodeName;
console.log(appCodeName);
// Output: Mozilla
7. Browser version
The `navigator.appVersion` to get the browser version.
const appVersion = navigator.appVersion;
console.log(appVersion);
// Output: 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36
8. Browser agent
Use the `navigator.userAgent` to get the user agent.
const userAgent = navigator.userAgent;
console.log(userAgent);
// Output: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! π