js 判斷IE瀏覽器,包含IE6/7/8/9

//判斷IE6-9的版本,num可取值爲6/7/8/9
//若不給參數num,僅判斷瀏覽器是否爲IE,不判斷版本瀏覽器

var isIE = function (num)
{
    if(arguments.length == 0){
        if (!!window.ActiveXObject || "ActiveXObject" in window)
      {
      return true;
    }
    else
      {
      return false;
    }
    }
    var browser = navigator.appName; 
    var b_version = navigator.appVersion; 
    var version = b_version.split(";"); 
    var trim_Version = version[1].replace(/[ ]/g,"");
    var version_num = 0;
    if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
    { 
        version_num = 6; 
    } 
    else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") 
    { 
        version_num = 7; 
    } 
    else if(browser == "Microsoft Internet Explorer" && trim_Version=="MSIE8.0") 
    { 
        version_num = 8; 
    } 
    else if(browser == "Microsoft Internet Explorer" && trim_Version=="MSIE9.0") 
    { 
        version_num= 9; 
    }
    return version_num==num?true:false;
}
相關文章
相關標籤/搜索