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);
}
用于检测浏览器以及系统环境的js
最新推荐文章于 2024-10-09 12:03:16 发布