Javascript code can detect the name and version of browsers. Javascript browser detection can be done by using methods, functions or properties of Javascript object navigator. Why Javascript browser detection is necessary these days? Yes its necessary coz there are number of internet users these days browsing websites. Every user is using different browser for surfing web sites according their ease of use. There are number features of websites that work on different browsers normally whereas shows erroneous response in others that depends on the version and name of the browsers. So, it becomes important for the designers as well as developers to detect the browser and perform the actions conditionally.

JavaScript navigator object

navigator.appName

returns the name of browser e.g.: Microsoft Internet Explorer, Netscape, Opera etc.

navigator.appVersion

returns the version of browser and the platform i.e. Operating system platform and other CLR installed on the client side.

navigator.appCodeName

returns the code name of browser, e.g.: Mozilla for all browsers instaled on Microsoft Windows platform.

JavaScript code to detect the browser

<script language="javascript" type="text/javascript">
    function detect() {
        document.getElementById("bName").innerHTML = navigator.appName;
        document.getElementById("bVersion").innerHTML = navigator.appVersion;
        document.getElementById("bCodeName").innerHTML = navigator.appCodeName;
    }
</script>

HTML code to display the Javascript browser detection parameters

<table
    border="0"
    cellpadding="2"
    cellspacing="0">
    <tr>
        <td>
            <strong>Browser Name:</strong>
        </td>
        <td>
            <div id="bName">
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <strong>Browser Version:</strong>
        </td>
        <td>
            <div id="bVersion">
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <strong>Browser CodeName: </strong>
        </td>
        <td>
            <div id="bCodeName">
            </div>
        </td>
    </tr>
</table> 

Place the javascript code in head of HTML page and call the detect function on body load.

e.g.:

<body onload="detect();">

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.