Navigator Object-tutorial
In JavaScript, the navigator object is part of the Browser Object Model (BOM) and provides important information about the user’s browser and system.
It helps developers detect browser details, platform type, and other useful properties for building adaptive and responsive web applications.
It helps developers detect browser details, platform type, and other useful properties for building adaptive and responsive web applications.
Key Properties of navigator object
Output
.webp)
- navigator.userAgent – Returns a string representing the user agent of the browser.
- navigator.appName – Gives the name of the browser.
- navigator.appVersion – Shows the version information of the browser.
- navigator.platform – Indicates the operating system/platform on which the browser is running.
- navigator.onLine – Boolean value that returns true if the browser is online, or false if offline.
Methods of navigator object
Example:
- navigator.geolocation – Access the user's geographic location (if supported by the browser and with user permission).
- navigator.getBattery() – Provides battery status information of the device.
Example:
<!DOCTYPE html><html>
<body> <h2>JavaScript Navigator Object</h2> <script> document.writeln("<br/>navigator.appCodeName: " + navigator.appCodeName); document.writeln("<br/>navigator.appName: " + navigator.appName); document.writeln("<br/>navigator.appVersion: " + navigator.appVersion); document.writeln("<br/>navigator.cookieEnabled: " + navigator.cookieEnabled); document.writeln("<br/>navigator.language: " + navigator.language); document.writeln("<br/>navigator.userAgent: " + navigator.userAgent); document.writeln("<br/>navigator.platform: " + navigator.platform); document.writeln("<br/>navigator.onLine: " + navigator.onLine); </script></body>
</html>
Output
.webp)