You are here: Reference > JavaScript > client-side > browser > objects > navigator

navigator object

Browser support:
Contains information about the browser and the operating system of the user.
Most members of the navigator object return information about the version of browser, and the platform running the browser.
The clientInformation object is an alias for the navigator object, but if you need cross-browser functionality use the navigator object.

Syntax:

Properties that reference the object:
window.navigator
The base interface, through which you can add new functionalities to the navigator object, is the Navigator interface.

Possible members:

Properties:
appCodeName
Retrieves the code name of the browser.
appMinorVersion
Returns the minor version of the browser.
appName
Returns the name of the browser.
appVersion
Returns the platform and version of the browser.
browserLanguage
Returns the language of the browser application or the operating system's user interface.
buildID
Retrieves the build identifier of the browser.
cookieEnabled
Retrieves a Boolean value that indicates whether cookies are enabled in the browser.
cpuClass
Returns the central processing unit (CPU) class of the user's operating system.
language
Returns the language of the browser application.
mimeTypes
Represents a collection of all supported MIME types.
onLine
Returns a Boolean value that indicates whether the browser is working online.
oscpu
Returns a string that contains information about the user's operating system and the central processing unit (CPU).
platform
Returns the name of the operating system platform.
plugins
Represents a collection of all installed plugins in the browser.
product
Returns a string that contains information about the browser engine.
productSub
Returns a string that contains information about the development build number of the browser engine.
systemLanguage
Returns the language edition of the operating system.
userAgent
Returns a string value that represents the user-agent header.
userLanguage
Returns the current Regional and Language settings of the operating system in Internet Explorer and the language of the browser application in Opera.
userProfile
9
Contains information about the current user's profile.
vendor
Returns a string that specifies the name of the browser vendor.
vendorSub
Returns a string that specifies the version number of the browser given by the vendor.
Methods:
javaEnabled
Returns a Boolean value that indicates whether Java is enabled in the current browser.
preference
Gets or sets a user preference. Only available in privileged code.
registerContentHandler
Allows registering a web site as a possible handler for content of the specified MIME type.
registerProtocolHandler
3
Allows registering a web site as a possible handler for a protocol.
taintEnabled
Returns a Boolean value that indicates whether the data-tainting security model is enabled.

Example HTML code 1:

This example shows how to detect the user's browser:
<head>
    <script type="text/javascript">
        function DetectBrowser () {
            var agent = navigator.userAgent.toLowerCase ();

            var browser = "Unknown browser";
            if (agent.search ("msie") > -1) {
                browser = "Internet Explorer";
            }
            else {
                if (agent.search ("firefox") > -1) {
                    browser = "Firefox";
                } 
                else {
                    if (agent.search ("opera") > -1) {
                        browser = "Opera";
                    } 
                    else {
                        if (agent.search ("safari") > -1) {
                            if (agent.search ("chrome") > -1) {
                                browser = "Google Chrome";
                            } 
                            else {
                                browser = "Safari";
                            }
                        }
                    }
                }
            }
            
            alert (browser);
        }
    </script>
</head>
<body>
    <button onclick="DetectBrowser ();">Detect Browser!</button>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example displays various information about the browser and the operating system of the user:
<head>
    <script type="text/javascript">
        function AddRowToInfo (description, value) {
            if (value !== undefined) {
                var infoTable = document.getElementById ("info");
                var row = infoTable.insertRow (-1);
                var cell = row.insertCell (-1);
                cell.innerHTML = description;
                cell.style.paddingRight = "10px";
                cell = row.insertCell (-1);
                cell.innerHTML = value;
                cell.style.paddingLeft = "10px";
            }
        }

        function GetVisitorInfo () {
            AddRowToInfo ("Name of the browser (appName)", window.navigator.appName);
            AddRowToInfo ("Name of the browser vendor (vendor)", window.navigator.vendor);
            AddRowToInfo ("Code name of the browser (appCodeName)", window.navigator.appCodeName);
            AddRowToInfo ("Engine of the browser (product)", window.navigator.product);
            AddRowToInfo ("Build number of the browser engine (productSub)", window.navigator.productSub);
            if (window.opera) {
                AddRowToInfo ("Build number of the browser (buildNumber)", window.opera.buildNumber ());
                AddRowToInfo ("Version number of the browser (version)", window.opera.version ());
            }
            AddRowToInfo ("Version and platform of the browser (appVersion)", window.navigator.appVersion);
            AddRowToInfo ("Version of the browser given by the vendor (vendorSub)", window.navigator.vendorSub);
            AddRowToInfo ("Minor version of the browser (appMinorVersion)", window.navigator.appMinorVersion);
            AddRowToInfo ("Build identifier of the browser (buildID)", window.navigator.buildID);
            AddRowToInfo ("User-agent request header (userAgent)", window.navigator.userAgent);
            AddRowToInfo ("Language of the browser (language)", window.navigator.language);
            AddRowToInfo ("Cookies are enabled (cookieEnabled)", window.navigator.cookieEnabled);

            AddRowToInfo ("Operating system (platform)", window.navigator.platform);
            if (window.navigator.language === undefined) {  // in Opera, the language, browserLanguage and userLanguage properties are equivalent
                AddRowToInfo ("Language of the operating system's user interface (browserLanguage)", window.navigator.browserLanguage);
                AddRowToInfo ("Regional and Language settings of the operating system (userLanguage)", window.navigator.userLanguage);
            }
            AddRowToInfo ("Language of the installed operating system (systemLanguage)", window.navigator.systemLanguage);
            AddRowToInfo ("Class of CPU (cpuClass)", window.navigator.cpuClass);
            AddRowToInfo ("Information about the OS and CPU (oscpu)", window.navigator.oscpu);
            AddRowToInfo ("System is online (onLine)", window.navigator.onLine);
        }
    </script>
</head>
<body onload="GetVisitorInfo ();">
    <table id="info" cellpadding="0px" cellspacing="0px" border="1px" style="empty-cells:show;">
        <colgroup>
            <col style="background-color: #e0a0b0;" />
            <col />
        </colgroup>
        <tbody>
        </tbody>
    </table>
</body>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content