BOM Windows Navigator Object In JavaScript

Introduction

This article will teach about BOM (Browser Object Model), JavaScript Navigator, and HistoryObject in JavaScript. In my previous article, I explained 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 in JavaScript

The JavaScript navigator object is used for browser detection. It can get browser information such as version and browser type.

The Navigator object has two features,

  • Methods and 
  • Properties

Methods in Navigator Object in JavaScript

The following table contains the methods of the JavaScript 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 in JavaScript

We can see the examples of location methods one by one,

The javaEnabled() Method in JavaScript

The JavaScript Navigator javaEnabled () method returns a Boolean value indicating whether 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.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>Navigator object Methods</title>  
</head>  
<body>  
    <h2>The javaEnabled () Method</h2>  
    <button ondblclick="java()">Click_To_Check</button>     
    <p id="javaEnabled"></p>   
    <script type="text/javascript">  
        function java() {   
            var ch ="Java Enabled is : " + navigator.javaEnabled();   
            document.getElementById("javaEnabled").innerHTML = ch;   
        }   
    </script>  
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The taintEnabled() Method in JavaScript

The JavaScript Navigator taintEnable() method was best avoided in Javascript version 1.5 and was later removed to prevent future run-time errors. It returns a false Boolean value, specifying whether the browser enables the data-tainting feature.

Syntax

navigator.taintEnabled ()

Example

The following programs illustrate the navigator taintEnabled () method in HTML.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>Navigator object Methods</title>  
</head>  
<body>  
    <h2>The taintEnabled () Method</h2>  
     <input type="button"value="Click to check" onClick="taint()">   
    
    <script language="JavaScript">   
        function taint() {   
            var temp = navigator.taintEnabled();   
            alert(window.navigator.taintEnabled());   
        }   
    </script>   
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

Property in Navigator Object in JavaScript

The following table contains the properties of the JavaScript 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 the 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 JavaScript Navigator object properties

We can see the examples of location properties in JavaScript one by one,

The appName property in JavaScript

This is a read-only property, and the values?? It is used to return the name of the browser. It provides vary from browser to browser.

Syntax

navigator.appName

Example

The following programs illustrate the navigator appName property in HTML.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>appName</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator appName property in JavaScript</h2>  
    <script>      
        document.write("Navigator.appName: "+navigator.appName);     
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The appcodeName property in JavaScript

It is used to return the code name of the browser. This is a read-only property that all modern browsers provide.

Syntax

navigator.appcodeName

Example

The following programs illustrate the navigator appcodeName property in HTML.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>appcodeName</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator appcodeName property in JavaScript</h2>  
    <script>      
        document.write("Navigator.appCodeName: "+navigator.appCodeName);    
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The appversion property in JavaScript

In JavaScript 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 JavaScript navigator appversion property in HTML.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>appversion</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator appversion property in JavaScript</h2>  
    <script>      
        document.write("Navigator.appVersion: "+navigator.appVersion);      
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The cookieEnabled property in JavaScript

It returns a Boolean value indicating whether the browser has enabled cookies. It returns true if the JavaScript Navigator cookie is enabled. Otherwise, it is false.

Syntax

navigator. cookieEnabled

Example

The following programs illustrate the navigator cookieEnabled property in HTML.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>cookieEnabled</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator cookieEnabled property in JavaScript</h2>  
    <script>      
        document.write("Navigator.cookieEnabled: "+navigator.cookieEnabled);     
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The onLine property in JavaScript

The JavaScript Navigator Online property returns 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.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>onLine</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator onLine property in JavaScript</h2>  
    <script>      
        document.write("Navigator.onLine: "+navigator.onLine);     
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The geoLocation property in JavaScript

The JavaScript 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 JavaScript Navigator geolocation property in HTML.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>geoLocation</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator geoLocation property in JavaScript</h2>  
    <script>      
        document.write("Navigator.appName: "+navigator.geolocation);     
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The language property in JavaScript

The JavaScript Navigator 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.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>language</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator language property in JavaScript</h2>  
    <script>      
        document.write("Navigator.language: "+navigator.language);     
    </script>    
</body>  
</html>  

Output

BOM Windows Navigator Object In JavaScript

The platform property in JavaScript

The JavaScript Navigator Platform property redirects 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.

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <title>platform</title>  
</head>  
<body>  
    <h2>BOM Windows object Navigator platform property in JavaScript</h2>  
    <script>      
        document.write("Navigator.platform: "+navigator.platform);     
    </script>    
</body>  
</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 helpful to you. Thanks for reading!