Home > Javascript > Function to Get Browser name

Function to Get Browser name


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))
            {
                 alert(”Chrome.”);
            }

           else if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
            {
                 alert(”Opera”);
            }
            else
            {
             alert(navigator.appName);
            }
             
            return false;
}

 window.onload  = GetBrowser;

Good Luck

Advertisements
Categories: Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: