JavaScript判斷瀏覽器類型及主版本

function getBrowserInfo(){
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject){
        Sys.b="ie";
        Sys.v =parseInt(ua.match(/msie ([\d.]+)/)[1]);
    }
    else if (document.getBoxObjectFor){
        Sys.b="firefox";
        Sys.v =parseInt(ua.match(/firefox\/([\d.]+)/)[1]);
    }
    else if (window.MessageEvent && !document.getBoxObjectFor){
        Sys.b="chrome";
        Sys.v == parseInt(ua.match(/chrome\/([\d.]+)/)[1]);
    }
    else if (window.opera){
        Sys.b="opera";
        Sys.v == parseInt(ua.match(/opera.([\d.]+)/)[1]);
    }
    else if (window.openDatabase){
        Sys.b="safari";
        Sys.v == parseInt(ua.match(/version\/([\d.]+)/)[1]);
    }
    return Sys;
}

var bi=getBrowserInfo();
document.write("Browser:"+bi.b+"    Version:"+bi.v);//Browser:ie Version:10

所屬標簽

無標簽

25选5玩法中奖