iPhone User Agent

403 views
Skip to first unread message

Chris

unread,
Jul 1, 2007, 3:06:19 PM7/1/07
to iPhoneWebDev
Just thought I'd post a little discovery... first, a very obvious
Tweet [1]:

iPhone User Agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538a Safari/
419.

Second, some code I found on Apple.com for testing for the iPhone [2]:

isiPhone: function(userAgent) {
var agent = userAgent || this.getAgent();
return agent.match(/iPhone/i);
},

Good to know.

Chris

[1] http://twitter.com/Damdam/statuses/111868822
[2] http://images.apple.com/global/scripts/browserdetect.js

Christopher Allen

unread,
Jul 1, 2007, 4:00:04 PM7/1/07
to iphone...@googlegroups.com
On 7/1/07, Chris <chris....@gmail.com> wrote:
> Just thought I'd post a little discovery... first, a very obvious
> Tweet [1]:
>
> iPhone User Agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
> AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538a Safari/
> 419.
>
> Second, some code I found on Apple.com for testing for the iPhone [2]:
>
> isiPhone: function(userAgent) {
> var agent = userAgent || this.getAgent();
> return agent.match(/iPhone/i);
> },

I'm recommending against useragent detection unless you are planning
iPhone-only site. For instance, there are some Nokia cell phones using
Safari also, and someday some of them will work with our web pages.

Instead, use CSS3 mediaqueries. Apple recommends for detecting iPhone:

iPhone:
<link media="only screen and (max-device-width:480px)" href
="small-devices.css" type="text/css" rel="stylesheet" />

(Note the use of the keyword 'only' so that old media query browsers
will work right)

Everthing else:
<link media="screen and (min-device-width:481 px)" href="not-small
device.css" type="text/css" rel="stylesheet" />

Of course, if you are going to use canvas you should do user agent
detection of safari, or if you are going to work-around iPhone
specific issues (i.e. things that work in Safari 3.0 but don't work on
the iPhone), the iPhone useragent detection is useful

-- Christopher Allen

Hardy...@gmail.com

unread,
Jul 1, 2007, 11:40:10 PM7/1/07
to iPhoneWebDev
How would I go about switching between the iphone version and the
desktop version of my website? Just switch the css files or should I
point to different starting files.

http://www.pointatme.com (iphone)
http://www.pointatme.com/about/ (others)

-Hardy

On Jul 1, 4:00 pm, "Christopher Allen" <Christoph...@iPhoneWebDev.com>
wrote:

Reply all
Reply to author
Forward
0 new messages