Javascript獲取瀏覽器信息、操作系統信息


<title>瀏覽器檢測</title>
<mce:script type="text/javascript"><!--
/**
* 客戶端信息檢測
*
* @類型:類
* @作者:[BI]CJJ http://www.imcjj.com
* @版本:0.1.3 build 061108
* @備注:
*/
function TClientCheck() {
    this.userAgent=navigator.userAgent;
    this.getBrowse=TClientCheck_Browse;
    this.getOS=TClientCheck_OS;
    this.browseKernel="unknown";
    this.isDOMSupport=false;//是否支持DOM
    if(document.getElementById) {
        this.isDOMSupport=true;
    }
}
/**
* 瀏覽器信息檢測
*
* @類型:公共方法
* @參數:無
* @返回:瀏覽器名稱
* @作者:[BI]CJJ http://www.imcjj.com
* @時間:2006-11-7 Last update at 2006-11-8
* @備注:
*/
function TClientCheck_Browse() {
    var sUA=this.userAgent;
     //檢測IE瀏覽器
    if ((navigator.appName == "Microsoft Internet Explorer")) {
        //檢測模擬IE瀏覽的OPERA。edit at 2006-11-08(ver 0.1.2)
        if (sUA.indexOf('Opera')!=-1) {
            this.browseKernel='Presto';
            if(window.opera && document.childNodes ) {
                return 'Opera 7+';
            } else {
                return 'Opera 6-';
            }
        }
        this.browseKernel='Trident';
        if(sUA.indexOf('Maxthon')!=-1) {
            return 'Maxthon';
        }
        if(sUA.indexOf('TencentTraveler')!=-1) { //ver 0.1.3
            return '騰迅TT';
        }
        if(document.getElementById) {
            return "IE5+";
        } else {
             return "IE4-";
        }
    }
    //檢測Gecko瀏覽器
    if(sUA.indexOf('Gecko')!=-1) {
        this.browseKernel='Gecko';
        if(navigator.vendor=="Mozilla") {return "Mozilla";}
        if(navigator.vendor=="Firebird") {return "Firebird"; }
        if (sUA.indexOf('Firefox')!=-1) {return 'Firefox';  }
        return "Gecko";
    }
    //Netscape瀏覽器
    if(sUA.indexOf('Netscape')!=-1) {
        this.browseKernel='Gecko';
        if(document.getElementById) {
            return "Netscape 6+";
        } else {
            return 'Netscape 5-';
        }
    }
    //檢測Safari瀏覽器
    if(sUA.indexOf('Safari') != -1) {this.browseKernel='KHTML';return 'Safari';}
    if(sUA.indexOf('konqueror')!=-1) {this.browseKernel='KHTML';return 'Konqueror';}
    //目前世界公認瀏覽網頁速度最快的瀏覽器,但它占用的系統資源也很大。
    if(sUA.indexOf('Opera') != -1) {
        this.browseKernel='Presto';
        if(window.opera && document.childNodes ) {
            return 'Opera 7+';
        } else {
            return 'Opera 6-';
        }
        return 'Opera';
    }
    if((sUA.indexOf( 'hotjava' )!=-1) && typeof( navigator.accentColorName ) == 'undefined' ) {return 'HotJava';}
    if( document.all && document.getElementById && navigator.savePreferences && (sUA.indexOf( 'netfront' ) < 0 ) && navigator.appName != 'Blazer' ) {return 'Escape 5'; }
    //Konqueror / Safari / OmniWeb 4.5+
    if( navigator.vendor == 'KDE' || ( document.childNodes && ( !document.all || navigator.accentColorName ) && !navigator.taintEnabled ) ) {this.browseKernel='KHTML';return 'KDE';}
    if( navigator.__ice_version ) { return 'ICEbrowser';}
    if( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) {
        if( document.createElement ) {
            return 'iCab 3+';
        } else {
            return 'iCab 2-';
        }
    }
    if(document.layers && !document.classes ) {return 'Omniweb 4.2-';}
    if(document.layers && !navigator.mimeTypes['*'] ) {return 'Escape 4';}
    if(navigator.appName.indexOf( 'WebTV' ) + 1 ) {return 'WebTV';}
    if(sUA.indexOf( 'netgem' )!=-1 ) {return 'Netgem NetBox';}
    if(sUA.indexOf( 'opentv' )!=-1 ) {return 'OpenTV';}
    if(sUA.indexOf( 'ipanel' )!=-1) {return 'iPanel MicroBrowser';}
    if(document.getElementById && !document.childNodes) {return 'Clue browser';}
    if(document.getElementById && ( (sUA.indexOf( 'netfront' ) !=-1) || navigator.appName == 'Blazer' ) ) {return 'NetFront 3+';}
    if((sUA.indexOf( 'msie' ) + 1 ) && window.ActiveXObject ) {return 'Pocket Internet Explorer'; }
    return "Unknown";
}
/**
* 操作系統信息檢測
*
* @類型:公共方法
* @參數:無
* @返回:操作系統名稱
* @作者:[BI]CJJ http://www.imcjj.com
* @時間:2006-11-7
* @備注:
*/
function TClientCheck_OS() {
    var sUA=this.userAgent.toLowerCase();
    if(sUA.indexOf( 'win' ) !=-1){
         if(sUA.indexOf("nt 5.2")!=-1) {return "Windows 2003";}
         if((sUA.indexOf("nt 5.1")!=-1)||(sUA.indexOf("XP")!=-1)) {return "Windows XP"; }
         if((sUA.indexOf('nt 5.0')!=-1) || (sUA.indexOf('2000')!=-1)) {return 'Windows 2000';}
         if((sUA.indexOf("winnt")!=-1) || (sUA.indexOf("windows nt")!=-1)) {return "Windows NT";}
         if((sUA.indexOf("win98")!=-1) || (sUA.indexOf("windows 98")!=-1)) {return "Windows 98";}
         return "Windows";
    }
    if(sUA.indexOf('linux')!=-1) {return 'Linux';}
    if(sUA.indexOf("freebsd")!=-1) {return 'FreeBSD';}
    if(sUA.indexOf( 'x11' )!=-1) {return 'Unix';}
    if(sUA.indexOf('mac') != -1) {return "Mac"; }
    if(sUA.indexOf("sunos")!=-1) {return 'Sun OS';}
    if((sUA.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (sUA.indexOf("ibm-webexplorer")!=-1)) {return "OS 2"}
    if(navigator.platform == 'PalmOS' ) {return 'Palm OS'; }
    if((navigator.platform == 'WinCE' ) || ( navigator.platform == 'Windows CE' ) || ( navigator.platform == 'Pocket PC' ) ) {return 'Windows CE';}
    if(sUA.indexOf( 'webtv')!=-1) {return 'WebTV Platform'; }
    if(sUA.indexOf( 'netgem')!=-1) {return 'Netgem';}
    if(sUA.indexOf( 'opentv')!=-1) {return 'OpenTV Platform';}
    if(sUA.indexOf( 'symbian')!=-1) {return 'Symbian';}
    return "Unknown";
}
// --></mce:script>
</head>
<body>
<div id="browseInfo">
</div>

Javascript獲取瀏覽器信息

<mce:script type="text/javascript"><!--
    var oCC=new TClientCheck();
    var oInfo=document.getElementById('browseInfo');
    oInfo.innerHTML='<p>您使用的是瀏覽器是:<b>'+oCC.getBrowse()+'</b></p><p>您使用的瀏覽器的內核是:<b>'+oCC.browseKernel+'</b></p><p>您使用的操作系統是:<b>'+oCC.getOS()+'</b></p><p>User Agent:'+oCC.userAgent+'</p>';
// --></mce:script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM