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.
Property | Description |
---|---|
appCodeName | Returns browser code name |
appName | Returns browser name |
appVersion | Returns browser version |
cookieEnabled | Returns true if browser cookies are enabled |
geolocation | Returns a geolocation object for the user’s location |
language | Returns browser language |
onLine | Returns true if the browser is online |
platform | Returns browser platform |
product | Returns browser engine name |
userAgent | Returns browser user-agent header |
Navigator Object Methods
Here are the methods of navigator objects.
Method | Description |
---|---|
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