Webkit.org has released a very nice detection script that is
compatible with both devices:
http://webkit.org/blog/119/webkit-detect-script-updated-for-iphone-and-ipod-touch/
But me being the ever-perfectionist iPhone developer, I've stripped
out what's not needed if all you need is i(Phone || Touch) detection:
var WebKitDetect = {
isWebKit : function() {
return new RegExp(" AppleWebKit/").test(navigator.userAgent);
},
isMobile : function() {
return WebKitDetect.isWebKit() && new RegExp("
Mobile/").test(navigator.userAgent);
},
mobileDevice : function() {
if (!WebKitDetect.isMobile()) {
return null;
}
var fields = new RegExp("(Mozilla/5.0 \\()([^;]
+)").exec(navigator.userAgent);
if (!fields || fields.length < 3) {
return null;
}
return fields[2];
}
};
Usage:
if (WebKitDetect.mobileDevice()) {
setInterval(updateLayout, 400);
}
On Sep 7, 9:56 am, Richard Herrera <docty...@gmail.com> wrote:
> A number of iPhone apps are using JS to sniff iPhone and serve content
> based on that. While I haven't seen the user agent string for the
> upcomingTouch, chances are likely it will not contain
> indexOf('iPhone'). This means it only takes one viewing for that newiPodTouchuser to declare that your app suxxors, et al.
>
> Webkit.org has released a very nice detection script that is
> compatible with both devices:http://webkit.org/blog/119/webkit-detect-script-updated-for-iphone-an...