Tuesday, February 28, 2012

Detecting IPhone Device

There are few ways you can detect Iphone Device, and tell browser to behave accordingly. The iPhone launched with this user agent:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

Todetect User Agent
Using ASP code
For those on a Windows Server, create a file called user-agent.asp and put the following lines of code in:
Response.Write Request.ServerVariables (“HTTP_USER_AGENT”)
Using PHP Code
For those on Linux based servers

Upload that to a server you have FTP access to, remember the URL, and type it in whenever you want. No need to worry about your IP address being recorded, either.


Alternatively you can create an HTML file like this
Your browser sends this User-Agent header:
<script type="text/javascript">
document.writeln( navigator.userAgent );
// -->

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

You can also use in CSS browser specific declarations to modify some style properties for just webkit.

/* This CSS increases the size of the paragraph elements */
p {
    -webkit-text-size-adjust: 125%;

Or you can do declarations inside a media type block

@media handheld, only screen and (max-device-width: 480px) {
    /* overrides or style additions for iPhone */

No comments:

Post a Comment