WebKit のブラウザ判定と iPhone、そして iPod touch

WebKit のブラウザ判定と iPhone、そして iPod touch

2007/09/09 5:05am

Prototype 1.6.0 のブラウザ判定と iPhone では、

prototype.js には 1.5.1 から、各種ブラウザを判定するための Prototype.Browser が定義されている。

として prototype.js のブラウザ判定コードを紹介した。iPhone を含む WebKit ベースのブラウザも判別できる。

WebKit Detect script

Surfin’ SafariWebKit Detect script updated for iPhone and iPod touch で知った。WebKit detection script というものがあるらしい。

記事では iPhoneiPod touch もサポートしたよ、と書かれている。ソースコードではこんな感じ、

WebKitDetect.isWebKit = function isWebKit()
{
    return RegExp(" AppleWebKit/").test(navigator.userAgent);
}
...
WebKitDetect.isMobile = function isMobile()
{
    return WebKitDetect.isWebKit() && RegExp(" Mobile/").test(navigator.userAgent);
}

つまり、User-Agent に、

ということのようだ。

ここで、prototype.js のブラウザ判定コードを復習してみる。

MobileSafari: !!navigator.userAgent.match(/iPhone.*Mobile.*Safari/)

User-Agent に “iPhone” という文字列を想定していることからも、おそらく iPod touch では動作しないだろう。まあ、すぐ直るだろうけど。