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 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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
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.
- <!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
Conclusion
In this article, we have seen the windows Navigator object in JavaScript. I hope this article is useful to you. Thanks for reading!