用于检测浏览器以及系统环境的js

var browsertype = '';
function checkbrowser(){
	var sUserAgent = navigator.userAgent;
	var sUsername = navigator.appName;
	//parseFloat 运行时逐个读取字符串中的字符,当他发现第一个非数字符是就停止
	var fAppVersion = parseFloat(navigator.appVersion);
	var browser = new Array();
    var isOpera = sUserAgent.indexOf("Opera") > -1 ;
    if(isOpera){
    	//首先检测Opera是否进行了伪装
    	var version;
    	if(navigator.appName == 'Opera'){
    		version = fAppVersion;//如果没有进行伪装,则直接后去版本号
    	}else{
    		var reOperaVersion = /Opera (\d+\.\d+)/;
    		reOperaVersion.exec(sUserAgent);//使用正则表达式的test方法测试并将版本号保存在RegExp.$1中
    		version = parseFloat(RegExp.$1);
    	}
    	browser[0] = "Opera";
		browser[1] = version;
    }
	
	// IE
	var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera; //!isOpera 避免是由Opera伪装成的IE
	if(isIE){
		var reIE = /MSIE (\d+\.\d+);/;
		reIE.exec(sUserAgent);
		var version = parseFloat(RegExp.$1);
		browser[0] = "Internet Explorer";
		browser[1] = version;
	}
	
	//Chrome
    var isChrome = sUserAgent.indexOf("Chrome") > -1 ;
    if(isChrome){
    	var reChorme = /Chrome\/(\d+\.\d+)/;
    	reChorme.exec(sUserAgent);
    	var version = parseFloat(RegExp.$1);
    	browser[0] = "Chrome";
		browser[1] = version;
    }
    
    //Safari
    //排除Chrome信息,因为在Chrome的user-agent字符串中会出现Konqueror/Safari的关键字
    var isKHTML = (sUserAgent.indexOf("KHTML") > -1 
                    || sUserAgent.indexOf("Konqueror") > -1 
                    || sUserAgent.indexOf("AppleWebKit") > -1) && !isChrome ;  
    if(isKHTML){//判断是否基于KHTML,如果时的话在继续判断属于何种KHTML浏览器
    	var isSafari1 = sUserAgent.indexOf("AppleWebKit") > -1;
    	var isKonq = sUserAgent.indexOf("Konqueror") > -1;
    	var version='';
    	if(isSafari1){
    		 var reAppleWebKit = /AppleWebKit\/(\d+\.\d+)/;
    		 reAppleWebKit.exec(sUserAgent);
    		 version = parseFloat(RegExp.$1);
    	}else if(isKonq){
    		var reKong = /Konqueror\/(\d+\.\d+)/;
    		reKong.exec(sUserAgent);
    		version = parseFloat(RegExp.$1);
    	}
    	browser[0] = "Safari";
		browser[1] = version;
    }
    
    //firefox 
    var isMoz = sUserAgent.indexOf("Gecko") > -1 && !isChrome &&!isKHTML; //排除Chrome 及Konqueror/Safari的伪装
    
    if(isMoz){
    	var reMoz = /rv:(\d+\.\d+)/;
    	reMoz.exec(sUserAgent);
    	var version = parseFloat(RegExp.$1);
    	browser[0] = "Firefox";
		browser[1] = version;
    }
    browsertype = browser[0]; 
    //检测结果
    $('#browser').html(browser[0]+' '+browser[1]);
    var imgname = 'iconWarning.jpg';
    switch(browser[0]){
    	case 'Internet Explorer':
    		if(browser[1]>=6){
    			imgname = 'good.png';
    		}
    		break;
    	case 'Chrome':
    		if(browser[1]>=8){
    			imgname = 'good.png';
    		}
        	break;
    	case 'Safari':
    		if(browser[1]>=2){
    			imgname = 'good.png';
    		}
        	break;
    	case 'Firefox':
    		if(browser[1]>=2){
    			imgname = 'good.png';
    		}
        	break;
    }
    var imgurl = '../../../images/'+imgname;
    $('#browser_img').attr('src',imgurl);
}

function checkfenbian(){
	$('#fenbian').html(screen.width+'x'+screen.height);
	var imgname = 'iconWarning.jpg';
	if(screen.width>=1024 && screen.height>=768){
		imgname = 'good.png';
	}
	var imgurl = '../../../images/'+imgname;
	$('#fenbian_img').attr('src',imgurl);
}

function checksystem(){
	var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
	var imgname = 'iconWarning.jpg';
	if(isWin){
		$('#system').html('Windows with '+browsertype);
		if(browsertype=='Internet Explorer' || browsertype=='Chrome' || browsertype=='Firefox'){
			imgname = 'good.png';
		}
	}
	var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
	if(isMac){
		$('#system').html('Mac with '+browsertype);
		if(browsertype=='Safari' || browsertype=='Chrome' || browsertype=='Firefox'){
			imgname = 'good.png';
		}		
	}
	var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
	if(isLinux){
		$('#system').html('Linux with '+browsertype);
		if(browsertype=='Firefox'){
			imgname = 'good.png';
		}	
	}
	var imgurl = '../../../images/'+imgname;
	$('#system_img').attr('src',imgurl);
}

/*检测flash版本*/
function checkflash(){
	var f="",n=navigator;
	if (n.plugins && n.plugins.length) {
		for (var ii=0;ii<n.plugins.length;ii++) {
			if (n.plugins[ii].name.indexOf('Shockwave Flash')!=-1) {
	   			var re = /Shockwave Flash (\d+)/;
	   			re.exec(n.plugins[ii].description);
	   			f = parseFloat(RegExp.$1);
	  			break;
	  		}
	 	}	
	} else if (window.ActiveXObject) {
	  	for (var ii=13;ii>=2;ii--) {
	  		try {   
	   				var fl=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+ii+"');");
	   				if (fl) {
		   				f=ii;
		   				break;
		   			}
	  		}
	 		catch(e) {}
	 	}
	}
	if(f!=''){
		if(f>=10){
			$('#flash').html('Flash Player '+f);
		}else{
			$('#flash').html('Flash Player '+f+"  <a href='http://get.adobe.com/cn/flashplayer/' target='_blank'>下载最新版本</a>");
		}	
	}else{
		$('#flash').html("没有安装Flash Player<br>点击<a href='http://get.adobe.com/cn/flashplayer/' target='_blank'>这里</a>安装");
	}
	var imgname = 'iconWarning.jpg';
	if(f>=10){
		imgname = 'good.png';
	}
	var imgurl = '../../../images/'+imgname;
	$('#flash_img').attr('src',imgurl);
		
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值