Created
August 17, 2012 05:15
-
-
Save leecade/3376147 to your computer and use it in GitHub Desktop.
js:browserinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from: http://hao.360.cn/zt/browserinfo.html | |
if(!window.console) | |
{ | |
console = {}; | |
console.log = function(){ | |
alert(Array.prototype.slice.call(arguments)); | |
}; | |
} | |
var browserDetector = (function(){ | |
// Useragent RegExp | |
var rwebkit = /(webkit)[ \/]([\w.]+)/, | |
ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/, | |
rmsie = /(msie) ([\w.]+)/, | |
rsafari = /(safari)[ \/]([\w.]+)/, | |
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/, | |
rfirefox = /(firefox)[ \/]([\w.]+)/, | |
rtrident = /(trident)[ \/]([\w.]+)/, | |
rgecko = /(gecko)[ \/]([\w]+)/, | |
rchrome = /(chrome)[ \/]([\w.]+)/, | |
rpresto = /(presto)[ \/]([\w.]+)/, | |
rshell = /(maxthon|360se|360ee|theworld|se|theworld|greenbrowser|mqqbrowser|qqbrowser|tencenttraveler)[ \/]?([\w.]*)/, | |
//device | |
randroid = /(android)[ \/]([\w.]+)/, | |
ripad = /(ipad)(?:.*os)? ([\d_]+)/, | |
riphone = /(iphone)(?:.*os)? ([\d_]+)/,//untested | |
//ripod = /(ipod)(?:.*os)? ([\d_]+)/,//untested | |
roperamini = /(opera mini)[ \/]([\w.]+)/,//untested | |
rblackberry = /(blackberry)([\d]+)/,//untested | |
rnokia = /(nokia)([\w]+)[ \/]///untested | |
rsymbian = /(symbianos)[ \/]([\w.]+)(?:.*)(series60)[ \/]([\w.]+)?///untested | |
rwinmob = /(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/,//untested | |
noneDouble=["",""],noneTriple = ["","",""]; | |
return function(ua){ | |
var info = {}; | |
//core---------- | |
var core = rchrome.exec( ua ) || | |
rsafari.exec( ua ) || | |
ropera.exec( ua ) || | |
rmsie.exec( ua ) || | |
rfirefox.exec( ua ) || | |
ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || | |
noneTriple; | |
//shell---------- | |
var shell = rshell.exec( ua )||noneTriple, | |
the360se = function(){ | |
try{ | |
var is360se = external.twGetRunPath.toLowerCase().indexOf("360se")>-1?true:false; | |
if(is360se) | |
{ | |
try{ | |
var version = external.twGetVersion(external.twGetSecurityID(window)); | |
return ["360se",version]; | |
}catch(e){ | |
return ["360se","-"]; | |
} | |
} | |
return noneDouble; | |
}catch(e){return noneDouble;} | |
}(), | |
theMaxthon = function() { | |
try { | |
if (/(\d+\.\d)/.test(external.max_version)) { | |
return ["maxthon",parseFloat(RegExp['\x241'])]; | |
} | |
return noneDouble; | |
} catch (e) {return noneDouble;} | |
}(); | |
//layout engine---------- | |
var layout = rtrident.exec( ua ) || | |
rwebkit.exec( ua ) || | |
rgecko.exec( ua ) || | |
rpresto.exec( ua ) || noneTriple; | |
//device---------- | |
var device = randroid.exec(ua)|| | |
riphone.exec(ua)|| | |
ripad.exec(ua)|| | |
roperamini.exec(ua)|| | |
rblackberry.exec(ua)|| | |
rnokia.exec(ua)|| | |
noneTriple; | |
if(!device[1]){ | |
var winmob = rwinmob.exec(ua); | |
if(winmob){ | |
device = ["","Windows Smartphone",""]; | |
}else{ | |
device = ["","Desktop","full capability browser"]; | |
} | |
}else if(device[1]==="android"){ | |
device = [device[0],"Mobile device","android "+device[2]]; | |
}else if(device[1]==="ipad"||device[1]==="iphone"){ | |
device[2] = "IOS "+device[2].replace(/_/g,"."); | |
}else if(device[1]==="nokia"){ | |
var symbian = rsymbian.exec(ua); | |
if(symbian) | |
device = ["",device[1]+device[2],"("+symbian[1]+"/"+symbian[2]+" "+symbian[3]+"/"+symbian[4]+")"]; | |
else | |
device = ["",device[1]+device[2],""]; | |
} | |
//----------- | |
info.layout = [layout[1],layout[2]]; | |
info.core = [core[1],core[2]]; | |
info.shell = [shell[1],shell[2]]; | |
if(the360se[0]){ | |
info.shell = the360se; | |
} else if(theMaxthon[0]) { | |
info.shell = theMaxthon; | |
} | |
info.script = function(){ | |
if(core[1]==="msie"){ | |
try{ | |
return [ScriptEngine(),[ScriptEngineMajorVersion(),ScriptEngineMinorVersion(),ScriptEngineBuildVersion()].join(".")]; | |
}catch(e){ | |
return noneDouble; | |
} | |
}else{ | |
return noneDouble; | |
} | |
}(); | |
info.documentMode = document.documentMode; | |
info.browserMode = function(){ | |
if(browserMode===7){ | |
if(layout[2]=="5.0"){ | |
browserMode += " (IE9兼容模式)" | |
}else if(core[2]=="8.0"||layout[2]=="4.0"){ | |
browserMode += " (IE8兼容模式)" | |
} | |
} | |
return browserMode; | |
}(); | |
info.compatMode = document.compatMode; | |
info.device = [device[1],device[2]]; | |
return info; | |
}; | |
})(); | |
(function(){ | |
var info = browserDetector(navigator.userAgent.toLowerCase()), | |
_d = function(id){return document.getElementById(id);}; | |
_d("browserCore").innerHTML = info.core.join(" / "); | |
_d("layoutEng").innerHTML = info.layout.join(" / "); | |
_d("scriptEng").innerHTML = info.script.join(" / "); | |
_d("compatMode").innerHTML = info.compatMode; | |
_d("browserShell").innerHTML = info.shell.join(" / "); | |
_d("device").innerHTML = info.device.join(" / "); | |
if(info.core[0]==="msie"&&/*@cc_on!@*/0){ | |
_d("browserMode").innerHTML = info.browserMode; | |
_d("documentMode").innerHTML = info.documentMode; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment