ろむのシ的メモ+α

Web系のブラウザゲーのツールとか作ったりつくらなかったりしてます

1行でのブラウザ判断について

Detecting browsers javascript hacks
この記事にある1行でのブラウザ判断を現時点での最新のものでテストしてみました
テストしたのは以下の5つ
Firefox3.6.8、Google Chrome5.0.375.127、Opera10.61、Safari5.0.1、IETester0.4.4のIE5.5と6

まずはFirefoxで下記を実行。共にfalseに。

//Firefox detector 2/3 by DoctorDan
FF=/a/[-1]=='a'

//Firefox 3 by me:-
FF3=(function x(){})[-5]=='x'

次にsafariで下記を実行。これはOKだった。

//Safari detector by me
Saf=/a/.__proto__=='//'

次にGoogle Chrome。これもNG。

//Chrome by me
Chr=/source/.test((/a/.toString+''))

そしてOpera。これもNG。

//Opera by me
Op=/^function \(/.test([].sort)

最後にIE6。これはIE5.5も引っかかった。

//IE6 detector using conditionals
try {IE6=@cc_on @_jscript_version <= 5.7&&@_jscript_build<10000} catch(e){IE6=false;}

NGが多くて結局userAgentからの判断にしたけど
こんな感じでそれぞれのブラウザ判断できる良い方法ないかな・・・