How to get browser name and version using JavaScript

in JavaScript / 1 Comment

Hi friends, In this post I am going to explain about how to get the browser name and there version using simple JavaScript function.

How to get browser name and version using JavaScript by Anil Kumar Panigrahi

How to get browser name and version using JavaScript by Anil Kumar Panigrahi

JavaScript Code

function detectBrowser(){
    var N= navigator.appName;
    var UA= navigator.userAgent;
    var temp;
    var browserVersion= UA.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
    if(browserVersion && (temp= UA.match(/version\/([\.\d]+)/i))!= null)
    browserVersion[2]= temp[1];
    browserVersion= browserVersion? "Browser:"+[browserVersion[1]+"\n Version:"+ browserVersion[2]]: [N, navigator.appVersion,'-?'];
    alert(browserVersion);
   
};

With more than 7 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : php.anil@gmail.com

Discussion 1 Comment

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>