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!
Also Read, Javascript hasOwnProperty
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 |
1 | appName | returns the name |
2 | appVersion | returns the version |
3 | appCodeName | returns the code name |
4 | cookieEnabled | returns true if cookie is enabled otherwise false |
5 | userAgent | returns the user agent |
6 | language | returns the language. It is supported in Netscape and Firefox only. |
7 | userLanguage | returns the user language. It is supported in IE only. |
8 | plugins | returns the plugins. It is supported in Netscape and Firefox only. |
9 | systemLanguage | returns the system language. It is supported in IE only. |
10 | mimeTypes[] | returns the array of mime type. It is supported in Netscape and Firefox only. |
11 | platform | returns the platform e.g. Win32. |
12 | online | It 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>