.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Java script function to get browser name.

Posted By:Virendra Dugar       Posted Date: October 07, 2009    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  

This javascript function will give you the web browser name and display as an alert message.

We have this requirement in most of the application to know that which browser user is using to view the web site. We can use javascript to know browser name and this function works with all the broswers.


function GetBrowser()
           if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
                 var ffversion=new Number(RegExp.$1) 
                 if (ffversion>=3)
                  alert("FF 3.x or above")
                 else if (ffversion>=2)
                  alert("FF 2.x")
                 else if (ffversion>=1)
                  alert("FF 1.x")
            else if(/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent))

           else if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
            return false;

 window.onload  = GetBrowser;


Further Readings:

Author: ConsultSarath         Company URL: http://www.dotnetspark.com
Posted Date: February 11, 2010

I have posted a snippet for the same using ASP.NET/VB.NET in my website http://www.consultsarath.com.

Article Link: http://www.consultsarath.com/CSSite/ShowArticle.aspx?KBId=2

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend