Home > DeveloperSection > Articles > JavaScript-Browser Compatibility

JavaScript-Browser Compatibility

JavaScript JavaScript 
0 Comment(s)
 3779  View(s)
Rate this:

JavaScript-Browser Compatibility


There are lots of browsers which are there in the market; we must know the differences between

those browsers. Different browsers support different tags so while designing the web page we must

know which browsers support which tags. We must know in which browser our web page is running.

To know on which browser our web page is running we will use the built-in Navigator object.

Navigator Properties:





It returns the code name of the browser.


It returns the name of the browser.


It returns the version information of the browser


It determines whether cookies are enabled in the browser.


It  returns true if the browser is online otherwise false.


It is a string. It returns for which platform the browser was compiled.


It contains the code name and version of the browser. This value is sent to the originating server to identify the client.


Navigator Object Methods:




It specifies whether Java is enabled or not.


It will return true or false based on whether Browser has data tainting enabled or not.



<html xmlns="http://www.w3.org/1999/xhtml">


    <script type="text/javascript">

        function findBrowse() {

            var userAgent = navigator.userAgent;

            var ie = (userAgent.indexOf('MSIE') != -1);

            var netscape = (userAgent.indexOf('Mozilla') != -1);

            var opera = (userAgent.indexOf('Opera') != -1);

            var version = navigator.appVersion;

            if (opera) {

                document.write("Opera code will execute");

            } else if (ie) {

                document.write("Internet Explorer based coding will execute");

            } else if (netscape) {

                document.write("Netscape Navigator coding will execute");


            else {

                document.write("Other Browser");








        <input id="btnFindBrowser" type="button" onclick="findBrowse()" value="Find Browser" />





If we run this code on Internet explorer then only the code block of Internet Explorer will execute.

This code is beneficial to when there are compatibility issues.



Example of Navigator Object Properties:



<html xmlns="http://www.w3.org/1999/xhtml">




    <script type="text/javascript">

        var appname = navigator.appName;

        document.write("Application Name : " + appname + "<br/>");

        var appversion = navigator.appVersion;

        document.write("Application version : " + appversion + "<br/>");

        var platform = navigator.platform;

        document.write("Platform for which the browser was compiled : " + platform +   


        var cookieEnabled = navigator.cookieEnabled

        if (cookieEnabled) {

            document.write("Cookie Enabled <br/>");


        else {

            document.write("Cookie not enabled");






Output :

JavaScript-Browser Compatibility



In the above example we have find the Application name which is the browser name, Application Version i.e.

 its version information, Platform for which the browser was compiled and whether the cookie is enabled or not.


In this article I explained about Navigator Object and what is the purpose of the Navigator Object.

Don't want to miss updates? Please click the below button!

Follow MindStick