Improving a Javascript browser detection function
<p>I’ve written a Javascript browser detection function but I’d like to improve it with everyone else’s knowledge.</p>

<p>Problems:</p>

<p>You’ll notice that I’m assuming that a “Chrome 18” must be a “Maxthon 3” but of course that is not necessarily so! </p>

<p>How can we differentiate between Chrome 18 and Maxthon 3?</p>

<p>Similarly, how can we differentiate between Firefox and Sea Monkey?</p>

<p>And what about Lunar? Can we also detect that browser via navigator.userAgent?</p>

<p>Is there any other popular browser I’ve forgotten about?</p>

<p>Only pure Javascript solutions/suggestions please!</p>

<pre><code> &lt;!DOCTYPE html&gt;

 &lt;script type="text/javascript"&gt;

 function GetBrowser(){
 var browser="";
 var version=0;

 if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
  version=new Number(RegExp.$1);
  browser="FireFox";} else {

  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
   version=new Number(RegExp.$1);
   browser="Internet Explorer";} else {

   if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
    version=new Number(RegExp.$1);
    browser="Opera";} else {

    if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
     version=new Number(RegExp.$1);
     if (version==18) {version=3; browser="Maxthon";} else {browser="Google Chrome"}} else {version=0; browser="Undetermined";}
 }}}
 return browser+' '+version;}

 document.write(GetBrowser());
 &lt;/script&gt;
</code></pre>
