Home > Style & Scripts > JavaScript > How to get browser name and version using JavaScript

How to get browser name and version using JavaScript

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);
   
};

1 Response

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.