Friday, March 30, 2012

Javascript - Detect Browser

function getInternetExplorerVersion()
{
    var rv = -1; // Return value assumes failure.
    
    //You can user "navigator.appName" to detect other browsers as well.
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
        {
             rv = parseFloat(RegExp.$1);
             if (rv > -1)
             {   
                 if (rv < 9.0)
                 {
                       alert("This is Not Microsoft Internet Explorer 9.0");
                       return;
                  }
             }
         }
      }
}