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
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.
1 2 3 4 | const platform = navigator.platform; console.log(platform); // Output: Win32 |
2. Browser language
The navigator.language
returns the language.
1 2 3 4 | 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.
1 2 3 4 | const onLine = navigator.onLine; console.log(onLine); // Output: true |
4. Browser cookies
The navigator.cookieEnabled
returns true if the cookie is enabled otherwise false.
1 2 3 4 | 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.
1 2 3 4 | 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.
1 2 3 4 | const appCodeName = navigator.appCodeName; console.log(appCodeName); // Output: Mozilla |
7. Browser version
The navigator.appVersion
to get the browser version.
1 2 3 4 | 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.
1 2 3 4 | 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..!! 🙂