Clue Mediator

Navigator object in JavaScript

πŸ“…June 18, 2021
πŸ—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

  1. Browser platform
  2. Browser language
  3. Is the browser online
  4. Browser cookies
  5. Browser application name
  6. Browser application code name
  7. Browser version
  8. 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..!! πŸ™‚