A browser sends a special string, called a user agent, to websites to identify itself. The web server, or JavaScript in the downloaded webpage, detects the client’s identity and can modify its behavior accordingly. In the simplest case, the user agent string includes an application name—for example, Navigator—and version information—for example, 6.0. Safari on the desktop, Safari on iPhone, and Safari on iPod touch have their own user agent strings, too.
The Safari user agent string for iPhone is similar to the user agent string for Safari on the desktop except for two additions: It contains an iPhone platform name and the mobile version number as show in Listing 2-3.
Listing 2-3 iPhone user agent string
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3 |
The parts of the Safari on iPhone user agent string shown in Listing 2-3 are as follows:
(iPhone; U; CPU like Mac OS X; en)The platform string.
AppleWebKit/420+The Web Kit engine build number.
Version/3.0The Safari family version.
Mobile/1A543The mobile version number.
Safari/419.3The Safari build number.
Typically, you use the Web Kit build number, AppleWebKit/420+, to test for supported Web Kit HTML tags and CSS properties. The Safari family version, or marketing version, Version/3.0, is included in the user agent string for Safari on the desktop, too. Therefore, you can use it to track usage statistics across all Safari platforms.
Go to these websites to learn more about other techniques for detecting Safari and the Web Kit:
webkit.org
http://trac.webkit.org/projects/webkit/wiki/DetectingWebKit
Contains JavaScript sample code for detecting Safari on iPhone and iPod touch.
developer.apple.com
http://developer.apple.com/internet/webcontent/objectdetection.html
Last updated: 2008-02-05