Home > DeveloperSection > Beginner > Detecting Browser Capability in Java Script

Detecting Browser Capability in Java Script


JavaScript JavaScript 
Ratings:
1 Comment(s)
 3995  View(s)
Rate this:

Detecting Browser Capability in Java Script

We know that java script work with client side browsers. Sometimes we want to know some information about client browser such as version number, name, and support cookie functionality or not. Depends upon the browser we send different-different pages and functionalities. The Navigator object contains information about the visitor's browser name, version, and more. Following table describes some common functionality regarding browser detection.

Property:

Ø  appCodeName  :  Provides code name of browser.

Ø  appName   :  Provides name of the browser that user use for viewing browser.

Ø  appVersion  :  Provides description of the version of browser.

Ø  cookieEnabled   :  Checks whether browser support whether cookie functionality enabled or not.

Following example demonstrate use of browser capability in java script

<script type="text/javascript">

        function detectBrowser() {

            document.write("Browser code name  : " + navigator.appCodeName + "<br />");

            document.write("Browser Name  : " + navigator.appName + "<br />");

            document.write("Browser Version  : " + navigator.appVersion + "<br />");

            document.write("Cookie Enabled  :  " + navigator.cookieEnabled + "<br />");

            document.write("Plateform  : " + navigator.platform + "<br />");

            document.write("User Agent Header  : " + navigator.userAgent + "<br />");

        }

</script>

Output of the following code snippet is as follows

Browser code name : Mozilla
Browser Name : Microsoft Internet Explorer
Browser Version : 4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Cookie Enabled : true
Platform : Win32
User Agent Header : Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)


Detecting browser capability in javascript

By Amit Singh on   5 years ago
Thanks Awadh,
This article is good one

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

Follow MindStick