HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

JavaScript Window Navigator

The window.navigator object provides information about the visitor's browser. It acts like a "detective" that can tell you which web browser is being used, which platform (OS) it is running on, and even whether the user is currently connected to the internet.


Browser identity Card

Here is what your browser tells JavaScript about itself right now:

Cookies Enabled: --
System Platform: --
Browser Language: --
Online Status: --
Detecting User Agent...

Browser Cookies

The cookieEnabled property returns true if cookies are enabled in the visitor's browser, and false otherwise.

if (navigator.cookieEnabled) {
    console.log("Cookies are allowed!");
} else {
    console.log("Cookies are disabled.");
}

The System Platform

The platform property returns the platform (operating system engine) for which the browser was compiled.

// Example outputs: "Win32", "MacIntel", "Linux x86_64"
console.log(navigator.platform);
Note: Some modern browsers may return generic strings for privacy reasons.

The User Agent

The userAgent property returns the user-agent header sent by the browser to the server. It contains deep details about the browser name, version, and the engine.

console.log(navigator.userAgent);

Internet Connection

The onLine property returns a boolean value stating whether the browser is working online or offline.

if (navigator.onLine) {
    alert("You are online!");
} else {
    alert("You are currently offline.");
}
Tip: This is very useful for web apps that need to save data locally when the user loses internet connection.

Navigator Object Summary

Property Description
navigator.cookieEnabled Returns true if cookies are enabled
navigator.userAgent Returns the user-agent string
navigator.language Returns the browser's language setting
navigator.onLine Returns true if the browser is online
navigator.platform Returns the system platform (e.g., Win32)
navigator.javaEnabled() Returns true if Java is enabled (Method)
Caution: The information from the navigator object can sometimes be misleading. For example, some browsers can "spoof" (fake) their user agent strings to appear as other browsers.

Key Points to Remember

  • The Navigator object provides specific details about the client's browser and system.
  • It is commonly used to detect **browser features** rather than browser names.
  • The onLine property helps detect connection drops.
  • The User Agent string is powerful but complex to parse manually.
  • Many old properties like appName are now "deprecated" and usually return "Netscape" for compatibility.