JS Navigator

Priyanka Patwal
Last Updated: May 13, 2022

Introduction

JavaScript Navigator object stores information about the visiting browser. It contains information like app name, app version, language, platform, etc. 

 

The Navigator object provides attributes that transmit information about the browser. The userAgent property, for example, is a property of the window.navigator object. The web browser is identified by a long string.


Since JavaScript Navigator is a window property, it can also be accessed with a window prefix.

For example, navigator can also be accessed as window.navigator


This article is all about the navigator object of JavaScript. So, let’s get started!

Properties in JavaScript Navigator

There are many properties associated with Navigator objects. Let's check them out!!

The following table denotes the various properties available in the Navigator:

No. Property Description
1appNamereturns the name
2appVersionreturns the version
3appCodeNamereturns the code name
4cookieEnabledreturns true if cookie is enabled otherwise false
5userAgentreturns the user agent
6languagereturns the language. It is supported in Netscape and Firefox only.
7userLanguagereturns the user language. It is supported in IE only.
8pluginsreturns the plugins. It is supported in Netscape and Firefox only.
9systemLanguagereturns the system language. It is supported in IE only.
10mimeTypes[]returns the array of mime type. It is supported in Netscape and Firefox only.
11platformreturns the platform e.g. Win32.
12onlineIt returns true if the browser is online; otherwise false.

 

We shall see the properties in detail:

1. appName:

The appName property is used to fetch the name of the browser

Syntax:

navigator.appName

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML ="navigator.appName is " + navigator.appName;
</script>

2. appVersion:

The appVersion property returns the version of the browser.

Syntax:

navigator.appVersion

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = navigator.appVersion;
</script>

3. appCodeName:

This property gives the application code name of the browser

Syntax:

navigator.appCodeName

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML =
"navigator.appCodeName is " + navigator.appCodeName;
</script>

4. cookieEnabled:

This property returns true if cookies are enabled. Otherwise, it returns false.

Syntax:

navigator.cookieEnabled

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML =
"cookiesEnabled is " + navigator.cookieEnabled;
</script>

5. userAgent:

This property returns the user-agent header sent by the browser to the server.

Syntax:

navigator.userAgent

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = navigator.userAgent;
</script>

6. language:

The language property gives us the browser’s language.

Syntax:

navigator.language

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = navigator.language;
</script>

7. userLanguage:

This property retrieves the operating system’s natural language setting.

Syntax:

navigator.userLanguage

Example:

<script type="text/javascript">
       function GetLangInfo () {
           var message = "";
           message += "<br />Regional and Language settings of the operating system: " +           window.navigator.userLanguage;
           }
          var output = document.getElementById ("output");
           output.innerHTML = message;
       }
   </script>

8. systemLanguage:

This property returns the language edition of the operating system.

          Syntax:

navigator.systemLanguage

 

          Example:

<script type="text/javascript">
       function GetLangInfo () {
           var message = "";
           message += "<br />Regional and Language settings of the operating system: " +           window.navigator.systemLanguage;
           }
          var output = document.getElementById ("output");
           output.innerHTML = message;
       }
   </script>

9. plugins:

This property returns a PluginArray object, listing the Plugin objects describing the plugins installed in the application.

Syntax:

navigator.plugins

Example:

var pluginsLength = navigator.plugins.length

10. mimeTypes

This property returns a MimeTypeArray object that contains a list of MimeType objects that represent the browser's MIME types.

Syntax:

navigator.mineTypes

Example:

function getJavaPluginDescription() {
 var mimetype = navigator.mimeTypes['application/x-java-applet'];
 if (mimetype === undefined) {
   // no Java plugin present
   return undefined;
 }
 return mimetype.enabledPlugin.description;
}

11. platform:

The platform property returns the browser operating system.

Syntax:

navigator.platform

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = navigator.platform;
</script>

12. online:

The onLine property returns true if the browser is online.

Syntax:

navigator.onLine

Example:

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = navigator.onLine;
</script>

Methods in JavaScript Navigator

There are two methods available in the JavaScript navigator object. 

  1. javaEnabled(): Specifies whether or not the browser has Java enabled.

Example: 

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = navigator.javaEnabled();
</script>

 

2. taintEnabled(): This function is used to check if taint is enabled. It is deprecated since JavaScript 1.2

Example:

var nav= navigator.taintEnabled()

This was all about the JavaScript Navigator Object. Let’s move on to faqs.

Frequently asked question

1). What is JavaScript Navigator?

Ans: JavaScript Navigator is an object in JS which returns information about the browser.


2). What kind of information can the navigator provide?

Ans: The navigator object can provide information like the name of the application, code name, version, if cookie is enabled, online status, etc.

 

3). What are the different methods in the navigator?

Ans: The navigator object has 2 methods:

  1. javaEnabled()
  2. taintEnabled()

Key Takeaways

JavaScript Navigator is a javascript object which provides us with information regarding the browser. It helps us find the name, code name, version, online status, cookie enable status, etc. 


This is done using different properties provided by navigator. JavaScript Navigator also has some methods to find the java enabled status of the browser.


We also have other interesting articles related to JavaScript like JavaScript Fetch APIFunction node.jsjQuery introduction and many more. Click the links to read more about the topics.


Happy learning!

Was this article helpful ?
0 upvotes

Comments

No comments yet

Be the first to share what you think