JavaScript: Detecting Browser; Browser Sniffing

, , …,
Want to master JavaScript in a month? Commit. Buy Xah JavaScript Tutorial. You also get Xah HTML Tutorial and Xah CSS 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.

to see various info about your browser.

Here's the code.

<p><button id="id52202">Click Me</button> to see various info about your browser.</p>

<div id="id55223"></div>
function ff() {

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

    var infoList = [ "<b>appName:</b> " + navigator.appName,
               "<b>version:</b> " + navigator.appVersion,
               "<b>Platform:</b> " + navigator.platform,
               "<b>appCodeName:</b> " + navigator.appCodeName,
               "<b>User agent:</b> " + navigator.userAgent,
               "<b>Cookies enabled:</b> " + navigator.cookieEnabled,
               "<b>Java enabled:</b> " + navigator.javaEnabled()

    for (var i = 0; i < infoList.length; i++) {
        newNode.innerHTML = newNode.innerHTML + "<li>" + infoList[i] + "</li>";

    // insert the new node into document
    var insertAt = document.getElementById("id55223");
    insertAt.parentNode.insertBefore(newNode, insertAt.nextSibling);


// add event to the button
document.getElementById("id52202").addEventListener("click", ff, false);

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.

blog comments powered by Disqus