Skip to content

Navigator object in JavaScript | API

  • by

The JavaScript navigator object is a property of the window object and contains browser information. You can use it to detect or get browser information such as appName, appCodeName, userAgent, etc.

The navigator object can be accessed by:

window.navigator  
//OR
navigator  

Navigator Object Properties

Here are the properties of the navigator object that returns information from the browser.

PropertyDescription
appCodeNameReturns browser code name
appNameReturns browser name
appVersionReturns browser version
cookieEnabledReturns true if browser cookies are enabled
geolocationReturns a geolocation object for the user’s location
languageReturns browser language
onLineReturns true if the browser is online
platformReturns browser platform
productReturns browser engine name
userAgentReturns browser user-agent header

Navigator Object Methods

Here are the methods of navigator objects.

MethodDescription
javaEnabled()Returns true if the browser has Java enabled
taintEnabled()Removed in JavaScript version 1.2 (1999).

Navigator object in JavaScript

Simple example code.

<!DOCTYPE html>
<html>
<head>
  <body>
    <script>
      console.log("appCodeName: ", navigator.appCodeName);  
      console.log("appName: ", navigator.appName);  
      console.log("appVersion: ", navigator.appVersion);  
      console.log("cookieEnabled: ", navigator.cookieEnabled);  
      console.log("language: ", navigator.language);  
      console.log("userAgent: ", navigator.userAgent);  
      console.log("platform: ", navigator.platform);  
      console.log("onLine: ", navigator.onLine);  

    </script>

</body>
</html>

Output:

These properties and methods can be useful for developing web applications that need to adapt their behavior based on the user’s browser environment. However, it’s important to note that the information provided by the Navigator object may not always be reliable, as user agents can be spoofed and certain features may not be available in all browsers.

Comment if you have any doubts or suggestions on this JS object topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading