JAVASCRIPT NAVIGATOR OBJECT

Lavanya



JavaScript  Navigator Object 


The JavaScript navigator object is used to detect the browser and retrieve information such as appName, appCodeName, userAgent, and more.

The navigator object is a property of the window, so it can be accessed using:


`window.navigator`

  Or

`navigator` 

Property of JavaScript Navigator Object 


The navigator object has many properties that provide information about the browser.



Method of JavaScript Navigator Object 


The methods of the navigator object are listed below.



Example of Navigator Object 


Let's explore the various uses of the history object.



Example 1: User Agent


<Script>

console.log(navigator.userAgent);

</Script>

Output:


`Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36`


Example 2: Browser Language


<Script>

console.log(navigator.language);

</Script>

Output:


`en-US`


Example 3: Browser Online Status

<Script>

console.log(navigator.onLine);

</Script>

Output:


`true` (or `false` if offline)


Example 4: Browser Cookies Enabled

<Script>

console.log(navigator.cookieEnabled);

</Script>

Output:


`true`


Example 5: Browser Name and Version

<Script>

console.log(navigator.appName);
console.log(navigator.appVersion);

</Script>

Output:


`Netscape`
`5.0 (Windows NT 10.0; Win64; x64)`


Example 6: Platform (Operating System)

<Script>

console.log(navigator.platform);

</Script>

Output:


`Win64`


Example 7: Geolocation Support

<Script>

if (navigator.geolocation) {
  console.log("Geolocation supported");
} else {
  console.log("Geolocation not supported");
}

</Script>

Output:


`Geolocation supported`


Example 8: MIME Types

<Script>

console.log(navigator.mimeTypes.length);

</Script>

Output:


`45` (number of MIME types supported)


Example 9: Plugins


<Script>

console.log(navigator.plugins.length);

</Script>

Output:


`10` (number of plugins installed)









Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send