//以用户代理字符串检测脚本,包括检测呈现引擎、平台、windows操作系统、移动设备和游戏系统。
var client = function(){
//呈现引擎
var engine = {
ie:0,
gecko:0,
webkit:0,
khtml:0,
opera:0,
//完整的版本号
ver:null
};
//浏览器
var browser = {
//主要浏览器
ie:0,
firefox:0,
safari:0,
konq:0,
opera:0,
chrome:0,
//具体的版本号
ver:null
};
//平台、设备和操作系统
var system = {
win:false,
mac:false,
x11:false,
//移动设备
iphone:false,
ipod:false,
ipad:false,
ios:false,
android:false,
nokian:false,
winmobile:false,
//游戏系统
wii:false,
ps:false
};
//检测呈现引擎和浏览器
var ua = navigator.useragent;
if(window.opera){
engine.ver = browser.ver = window.opera.version();
engine.opera = browser.opera = parsefloat(engine.ver);
}
else if(/applewebkit\/(\s+)/.test(ua)){
engine.ver = regexp["$1"];
engine.webkit = parsefloat(engine.ver);
//确定是chrome还是safari
if(/chrome\/(\s+)/.test(ua)){
browser.ver = regexp["$1"];
browser.chrome = parsefloat(browser.ver);
}
else if(/version\/(\s+)/.test(ua)){
browser.ver = regexp["$1"];
browser.safari = parsefloat(browser.ver);
}
else{
//近似的确定版本号
var safariversion = 1;
if(engine.webkit<100){
safariversion = 1;
} else if(engine.webkit<312){
safariversion = 1.2;
} else if(engine.webkit<412){
safariversion = 1.3;
} else{
safariversion = 1;
}
browser.safari = browser.ver = safariversion;
}
}
else if(/khtml\/(\s+)/.test(ua)||/kongqueror\/([^;]+)/.test(ua)){
engine.ver = browser.ver = regexp["$1"];
engine.khtml = browser.konq = parsefloat(engine.ver);
}
else if(/rv:([^\)]+)\) gecko\/\d{8}/.test(ua)){
engine.ver = regexp["$1"];
engine.gecko = parsefloat(engine.ver)
//确定是不是firefox
if(/firefox\/(\s+)/.test(ua)){
browser.ver = regexp["$1"];
browser.firefox = parsefloat(browser.ver);
}
}
else if(/msie ([^;]+)/.test(ua)){
engine.ver = browser.ver = regexp["$1"];
engine.ie = browser.ie = parsefloat(engine.ver);
}
//检测浏览器
browser.ie = engine.ie;
browser.opera = engine.opera;
//检测平台
var p = navigator.platform;
system.win = p.indexof("win")==0;
system.mac = p.indexof("mac")==0;
system.x11 = (p = "x11")||(p.indexof("linux")==0);
//检测windows操作系统
if(system.win){
if(/win(?:dows )?([^do]{2})\s?(\d+\.\d+)?/.test(ua)){
if(regexp["$1"]=="nt"){
switch(regexp["$2"]){
case "5.0":
system.win = "2000";
break;
case "5.1":
system.win = "xp";
break;
case "6.0":
system.win = "visita";
break;
case "6.1":
system.win = "7";
break;
default:
system.win = "nt";
break;
}
}
else if(regexp["$1"]=="9x"){
system.win = "me";
}
else {
system.win = regexp["$1"];
}
}
}
//移动设备
system.iphone = ua.indexof("iphone")>-1;
system.ipod = ua.indexof("ipod")>-1;
system.ipad = ua.indexof("ipad")>-1;
system.nokian = ua.indexof("nokian")>-1;
//windows moblie
if(system.win=="ce"){
system.winmobile = system.win;
} else if(system.win == "ph"){
if(/windows phone os (\d+.\d+)/.test(ua)){
system.win = "phone";
system.winmobile = parsefloat(regexp["$1"]);
}
}
//检测ios版本
if(system.mac&&ua.indexof("mobile")>-1){
if(/cpu (?:iphone)?os (\d+_\d+)/.test(ua)){
system.ios = parsefloat(regexp.$1.replace("_","."));
} else{
system.ios = 2;//不能真正检测出来,所以只能猜测
}
}
//检测android版本
if(/android (\d+\.\d+)/.test(ua)){
system.android = parsefloat(regexp.$1);
}
//游戏系统
system.wii = ua.indexof("wii")>-1;
system.ps = /playstation/i.test(ua);
//返回这些对象
return {
engine:engine,
browser:browser,
system:system
};
}();
/*
for(p in client.engine){
document.write("client.engine."+p+":"+client.engine[p]+"
");
}
document.write("