Home > Ext | JavaScript | Sencha > PlatformSelector.js

PlatformSelector.js

ども、小堤です。
ツイッターくらいしか、書いてないんですが、ブログ放置ですね。完璧。

んで、またどーでもいいものなんですが、PlatformSelector.jsです。
Sencha Touchとか、Ext Coreとか読み込む前に、そもそもiPhoneの時にリダイレクトとかしたいときに使えるもんです。

サーバーサイドで判定できない仕事もあるもんで(やってるんですが)
あると便利かな。と。

さらしときます(笑)

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

PlatformSelector = {
    isWebkit: /webkit/i.test(navigator.userAgent.toLowerCase()),
    isPhone: /android|iphone/i.test(navigator.userAgent.toLowerCase()) && !(/ipad/i.test(navigator.userAgent.toLowerCase())),
    isTablet: /ipad/i.test(navigator.userAgent.toLowerCase()),
    isChrome: /chrome/i.test(navigator.userAgent.toLowerCase()),
    isAndroidOS: /android/i.test(navigator.userAgent.toLowerCase()),
    isIPhoneOS: /iphone|ipad/i.test(navigator.userAgent.toLowerCase()),
    hasOrientationChange: ('onorientationchange' in window),
    hasTouch: ('ontouchstart' in window)
};

if(PlatformSelector.isTablet) {
    location.href = 'ipad.html';
} else if(PlatformSelector.isPhone && PlatformSelector.isIPhoneOS) {
    location.href = 'iphone.html';
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * End:
 */

Trackbacks:1

Trackback URL for this entry
http://code.xenophy.com/wp-trackback.php?p=1047
Listed below are links to weblogs that reference
PlatformSelector.js from code:x
trackback from Krabpalen 2010/9/8 水曜日

Goedkope krabpalen

De specialist in goedkope krabpalen

Home > Ext | JavaScript | Sencha > PlatformSelector.js

Search
Feeds
Meta

Return to page top