The navigator object in Javascript provides information about the browser and the user's system.
It is a part of the Browser Object Model (BOM) and is used in web applications for various purposes such as detecting the browser type(Agent), language detection, handling offline/online status, access geolocation data and platform Information.
`navigator.userAgent`: Returns a string representing the user agent of the browser. It contains information about the browser, version, and operating system.
console.log("User Agent:", navigator.userAgent);
`navigator.language`: Returns a string representing the user's preferred language.
console.log("Preferred Language:", navigator.language);
`navigator.platform`: Returns a string representing the platform of the browser (e.g., "Win32" or "MacIntel").
console.log("Platform:", navigator.platform);
`navigator.onLine`: Returns a boolean indicating whether the browser is online or offline.
console.log("Online Status:", navigator.onLine);
`navigator.geolocation`: Provides access to the geolocation services, allowing you to obtain the user's current location.
if ('geolocation' in navigator) { navigator.geolocation.getCurrentPosition(function(position) { console.log("Latitude:", position.coords.latitude); console.log("Longitude:", position.coords.longitude); }); } else { console.log("Geolocation not supported"); }
`navigator.cookieEnabled`: Returns a boolean indicating whether cookies are enabled in the browser.
console.log("Cookies Enabled:", navigator.cookieEnabled);
`navigator.plugins`: Returns an array of Plugin objects, representing the plugins installed in the browser.
console.log("Number of Plugins:", navigator.plugins.length);