
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the importance of Navigator Object in JavaScript?
The JavaScript navigator object is used for browser detection, it can be used to get browser information such as appName, appCodeName, userAgent, etc. Navigator object is a window property so it can be accessed by the "window.navigator" or "navigator".
It can also check whether the browser is in online mode or not and whether Java is enabled or not in our system.
There are many properties of navigator objects that return information about the browser following are some of those −
appName − Returns the name
appVersion − Returns the version
appCodeName − Returns the code name
cookieEnabled − Returns true if the cookie is enabled otherwise false
userAgent − Returns the user agent
language − Returns the language. It is supported in Netscape and Firefox only.
userLanguage − Returns the user language. It is supported in IE only.
plugins − Returns the plugins. It is supported in Netscape and Firefox only.
systemLanguage − Returns the system language. It is supported in IE only.
mimeTypes[] − Returns the array of mime types. It is supported in Netscape and Firefox only.
platform − Returns the platform e.g. Win32.
online − Returns true if the browser is online otherwise false.
Example: 1
In the following example, we are checking the few properties whether it is working or not. If you want to check the all properties just only change the properties name.
<!DOCTYPE html> <html> <head> <title>navigator objet</title> </head> <body> <script> document.writeln("<br/>navigator.appCodeName : " + navigator.appCodeName); document.writeln("<br/>navigator.appName : " + navigator.appName); document.writeln("<br/>navigator.appVersion : " + navigator.appVersion); document.writeln("<br/>navigator.cookieEnabled : " + navigator.cookieEnabled); document.writeln("<br/>navigator.language : " + navigator.language); document.writeln("<br/>navigator.userAgent : " + navigator.userAgent); document.writeln("<br/>navigator.platform : " + navigator.platform); document.writeln("<br/>navigator.onLine : " + navigator.onLine); </script> </body> </html>
Example 2
In the following example, we are checking the method if we have installed the java or not in our pc. But in our pc java is not installed i.e. the output is false.
<!DOCTYPE html> <html> <head> <title>navigator objet</title> </head> <body> <script> var check = "Is java Enabled in your pc : " + navigator.javaEnabled(); document.write(check); </script> </body> </html>
Example 3
The following example demonstrates the importance of the navigator object in JavaScript.
In this case, we will use the navigator object to obtain browser information to check if your browser is in online mode. If so then it displays true if it is in online mode else returns false and it displays the necessary browser information.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>JavaScript Navigator Object example</title> <div id="check"></div> </head> <body> <script type="text/javascript"> let x = "Is your browser is in online mode? " + navigator.onLine; document.getElementById("check").innerHTML = x; </script> </body> </html>
- Related Articles
- What is the role of Navigator object in JavaScript?
- What is the importance of "enumerable" attribute in defining a property in JavaScript object?
- What is the importance of Symbol.isConcatSpreadable in JavaScript?
- What is the importance of _isEqual() method in JavaScript?
- What is the importance of _without() method in JavaScript?
- What is the importance of _.initial() function in JavaScript?
- What is the importance of _.union() method in JavaScript?
- What is the importance of str.padStart() method in JavaScript?
- What is the importance of Math.trunc() method in JavaScript?
- What is importance of startsWith() method in JavaScript?
- What is the importance of '/g' flag in JavaScript?
- What is the importance of '/i' flag in JavaScript?
- What is the importance of ES6's template strings in JavaScript?
- What is the importance of '+' operator in type conversion in JavaScript?
- What is the use of proxy() object in JavaScript?
