BOM Windows Navigator Object In JavaScript

Introduction

 
In this article, we will learn about BOM (Browser Object Model) Navigator and HistoryObject in JavaScript. In my previous article, I explained about BOM object methods and properties. If you  want to read the article click the link.
 
The BOM (Browser model objects) are:
  • Windows Object
  • Navigator Object
  • Location Object
  • Screen Object
  • Storage Object

The Navigator Object

 
Navigator object is used for browser detection. It can be used to get browser information such as version and browser type.
 
In the Navigator object has the two features,
  • Methods and 
  • Properties
Methods in Navigator Object
 
The following table contains the methods of the Navigator object in JavaScript.
  • Methods
  • Description
  • javaEnabled ()
    It Specifies whether or not Java is enabled in the browser.
  • taintEnabled ()
    It Specifies whether the data field is enabled in the browser.
Examples of Navigator object Methods
 
We can see the examples of location methods one by one,
 

The javaEnabled () Method

 
The Navigator javaEnabled () method is used to return a Boolean value that indicates whether or not Java is enabled in a browser. If Java is enabled in the browser it returns true else it returns false.
 
Syntax
 
navigator.javaEnabled ()
 
Example
 
The following programs illustrate the navigator javaEnabled () method in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>Navigator object Methods</title>  
  6. </head>  
  7. <body>  
  8.     <h2>The javaEnabled () Method</h2>  
  9.     <button ondblclick="java()">Click_To_Check</button>     
  10.     <p id="javaEnabled"></p>   
  11.     <script type="text/javascript">  
  12.         function java() {   
  13.             var ch ="Java Enabled is : " + navigator.javaEnabled();   
  14.             document.getElementById("javaEnabled").innerHTML = ch;   
  15.         }   
  16.     </script>  
  17. </body>  
  18. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The taintEnabled ()Method

 
The Navigator taintEnable () method was best avoided in Javascript version 1.5, and was later removed to prevent future run-time errors. It returns a Boolean value false value, specifying whether the data-tainting feature is enabled in the browser.
 
Syntax
 
navigator.taintEnabled ()
 
Example
 
The following programs illustrate the navigator taintEnabled () method in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>Navigator object Methods</title>  
  6. </head>  
  7. <body>  
  8.     <h2>The taintEnabled () Method</h2>  
  9.      <input type="button"value="Click to check" onClick="taint()">   
  10.     
  11.     <script language="JavaScript">   
  12.         function taint() {   
  13.             var temp = navigator.taintEnabled();   
  14.             alert(window.navigator.taintEnabled());   
  15.         }   
  16.     </script>   
  17. </body>  
  18. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

Property in Navigator Object

 
The following table contains the properties of the Navigator object in JavaScript.
 
Properties
Descriptions
appName
It specifies the name of the browser.
appVersion
It specifies the version of the browser being.
appcodeName
It specifies code name of the browser
cookieEnabled
It specifies whether cookies are enabled in the browser or not
onLine
It returns true if the browser is online otherwise false.
geoLocation
It provides a geolocation object that can be used to track the user's status
language
It returns the browser language
platform
It returns which platform browser complied
 
Examples of Navigator object properties
 
We can see the examples of location properties one by one,
 

The appName property

 
It is used to return the name of the browser. This is a read-only property and the values ​​it provides vary from browser to browser.
 
Syntax
 
navigator.appName
 
Example
 
The following programs illustrate the navigator appName property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>appName</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator appName property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.appName: "+navigator.appName);     
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The appcodeName property

 
It is used to return the code name of the browser. This is a read-only property and all modern browsers provide.
 
Syntax
 
navigator.appcodeName
 
Example
 
The following programs illustrate the navigator appcodeName property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>appcodeName</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator appcodeName property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.appCodeName: "+navigator.appCodeName);    
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The appversion property

 
In Navigator appVersion specifies the version of the browser. It returns a string representing the version information of the browser.
 
Syntax
 
navigator.appversion
 
Example
 
The following programs illustrate the navigator appversion property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>appversion</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator appversion property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.appVersion: "+navigator.appVersion);      
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The cookieEnabled property

 
It returns true if the Navigator cookie is enabled, otherwise it is false. It returns a Boolean value that indicates whether or not the browser has enabled cookies.
 
Syntax
 
navigator. cookieEnabled
 
Example
 
The following programs illustrates the navigator cookieEnabled property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>cookieEnabled</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator cookieEnabled property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.cookieEnabled: "+navigator.cookieEnabled);     
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The onLine property

 
The Navigator Online property is used to return a Boolean value indicating whether a browser is online or false.
 
Syntax
 
navigator.onLine
 
Example
 
The following programs illustrate the navigator onLine property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>onLine</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator onLine property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.onLine: "+navigator.onLine);     
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The geoLocation property

 
The Navigator geoLocation property provides a geolocation object that can be used to track the user's status.
 
Syntax
 
navigator. geoLocation
 
Example
 
The following programs illustrate the navigator geolocation property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>geoLocation</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator geoLocation property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.appName: "+navigator.geolocation);     
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The language property

 
TheNavigator language property is used to return the language version of the browser. E.g. en-us, fr, en, de.
 
Syntax
 
navigator. language
 
Example
 
The following programs illustrate the navigator language property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>language</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator language property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.language: "+navigator.language);     
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

The platform property

 
The Navigator Platform property is used to redirect the browser to the compiled site. It returns a string representing the browser's site. E.g. win32, win16, linuxi686
 
Syntax
 
navigator. platform
 
Example
 
The following programs illustrate the navigator platform property in HTML.
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>platform</title>  
  6. </head>  
  7. <body>  
  8.     <h2>BOM Windows object Navigator platform property in JavaScript</h2>  
  9.     <script>      
  10.         document.write("Navigator.platform: "+navigator.platform);     
  11.     </script>    
  12. </body>  
  13. </html>  
Output
 
BOM Windows Navigator Object In JavaScript
 

Conclusion

 
In this article, we have seen the windows Navigator object in JavaScript. I hope this article is useful to you. Thanks for reading!