下面是一些另类的但挺高效的浏览器探测技巧,主要利用了各浏览器的私有特征完成。
进入正题:
//Firefox detector 2/3 by DoctorDan(slackers论坛)
FF=/a/[-1]=='a'
//Firefox 3
FF3=(function x(){})[-5]=='x'
//Firefox 2
FF2=(function x(){})[-6]=='x'
//IE
IE='\v'=='v'
//Safari
Saf=/a/.__proto__=='//'
//Chrome
Chr=/source/.test((/a/.toString+''))
//Opera by me
Op=/^function \(/.test([].sort)
//IE6
try {IE6=@cc_on @_jscript_version <= 5.7&&@_jscript_build<10000} catch(e){IE6=false;}
整合到一行:
B=(function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/