JavaScript: Browser Info, Navigator Object

, , …,
Want to master JavaScript in a week? Buy Xah JavaScript Tutorial.

This pages shows you how to use JavaScript to find various info about browser. For example, whether cookies is on, java is installed, or about browser version.

Most info about browsers are in the object navigator. Here's the navigator object's properties supported by all browsers, and what your browser shows, orderly roughly in practical usefulness:

Here's the code.

<div id="showinfo55223"></div>
function showBrowserInfo() {

    // create node
    var newNode = document.createElement("ul");

    var infoList = 
        [ 
            "<b>appName:</b> " + navigator.appName,
            "<b>appCodeName:</b> " + navigator.appCodeName,
            "<b>appVersion:</b> " + navigator.appVersion,
            "<b>Platform:</b> " + navigator.platform,
            "<b>appCodeName:</b> " + navigator.appCodeName,
            "<b>product:</b> " + navigator.product,
            "<b>userAgent:</b> " + navigator.userAgent,
            "<b>cookieEnabled:</b> " + navigator.cookieEnabled,
            "<b>javaEnabled:</b> " + navigator.javaEnabled(),
            "<b>mimeTypes:</b> " + JSON.stringify(navigator.mimeTypes),
            "<b>plugins:</b> " + JSON.stringify(navigator.plugins),
        ];

    for (var i = 0; i < infoList.length; i++) {
        var liNode = document.createElement("li");
        liNode.innerHTML=infoList[i];
        newNode.appendChild(liNode);

    }

    // insert the new node into document
    var anchor = document.getElementById("showinfo55223");
    if ( anchor.hasChildNodes() ) {
        anchor.removeChild(anchor.lastChild)
    }
    anchor.appendChild(newNode);

}

showBrowserInfo();

navigator.cookieEnabled returns a Boolean type. The value is auto converted to string when in string context.

javaEnabled() is a method, not property. It returns a Boolean type. It is also auto converted to string here.

Reference

https://developer.mozilla.org/en-US/docs/Web/API/Navigator

blog comments powered by Disqus