Home > DeveloperSection > Blogs > Detect Browser Information using JavaScript

Detect Browser Information using JavaScript


JavaScript JavaScript 
Ratings:
0 Comment(s)
 2765  View(s)
Rate this:

Detect Browser Information Using JavaScript


In this blog I am going to explain how to detect browser information using java script such as browser name, browser version, whether cookies are enabled or not in a browser, platform etc.

Create a table that display’s the browser information:

<table>

        <tr>

            <td>

                <span>Browser Name:</span>

            </td>

            <td>

                <label id="appName">

                </label>

            </td>

        </tr>

        <tr>

            <td>

                <span>Browser Version:</span>

            </td>

            <td>

                <label id="appVersion">

                </label>

            </td>

        </tr>

        <tr>

            <td>

                <span>Cookies Enabled:</span>

            </td>

            <td>

                <label id="cookieEnabled">

                </label>

            </td>

        </tr>

        <tr>

            <td>

                <span>Platform:</span>

            </td>

            <td>

                <label id="platform">

                </label>

            </td>

        </tr>

        <tr>

            <td>

                <span>User-agent header</span>

            </td>

            <td>

                <label id="userAgent">

                </label>

            </td>

        </tr>

        <tr>

            <td colspan="2">

                <input type="button" value="Check Browser Information" onclick="getBrowserInfo()" />

            </td>

        </tr>

    </table>

After creating the layout, call the java script function as shown below:

<script type="text/javascript">

        function getBrowserInfo() {

            document.getElementById("appName").innerHTML = navigator.appName;

            document.getElementById("appVersion").innerHTML = navigator.appVersion;

            document.getElementById("cookieEnabled").innerHTML = navigator.cookieEnabled;

            document.getElementById("platform").innerHTML = navigator.platform;

            document.getElementById("userAgent").innerHTML = navigator.userAgent;

        }

</script>

After creating the above you can easily detect the browser information.


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

Follow MindStick