↑
Main Page
Safari
The important things to note in this string are the following:
1.
The Mozilla version is set to 4.0, just like IE 6.0.
2.
The string
“compatible”
is present.
3.
The string
“MSIE”
is present.
These three things accurately mimic IE 5.0’s user-agent string.
Safari
In 2004, Apple introduced its own browser called Safari. Safari is based on another open source project
called KHTML, which is the main component of the Unix-based Konqueror Web browser. Apple created
the Apple Web Kit from KHTML, providing Macintosh developers with their first official Web technol-
ogy platform. Safari was created as an application of the Apple Web Kit and now ships as the default
Web browser with all copies of MacOS X. By doing this, Apple instantly created a segment of the market
that will be using Safari for a long time to come.
The basic format of the Safari user-agent string is the following:
Mozilla/5.0 (Platform; Security; OS-or-CPU; Language)
AppleWebKit/AppleWebKitVersion (KHTML, like Gecko) Safari/SafariVersion
For example:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/124 (KHTML, like Gecko)
Safari/125.1
As you can see, this is another long user-agent string. It takes into account not only the version of the
Apple Web Kit but also the Safari version. A point of contention over whether to identify the browser as
Mozilla was solved rather quickly for compatibility reasons. Now, all Safari browsers identify them-
selves as Mozilla 5.0, the same as all Mozilla browsers. The Safari version has typically been the build
number of the browser, not necessarily a representation of the release version number. So although
Safari 1.25 has the number 125.1 in the user-agent string, there may not always be a one-to-one match.
The most interesting and controversial part of this user-agent string is the addition of the string
“(KHTML, like Gecko)”
in a pre-1.0 version of Safari. Apple got a lot of pushback from developers
who saw this as a blatant attempt to trick clients and servers into thinking Safari was actually Mozilla
(as if adding Mozilla/5.0 wasn’t enough). Apple’s response was similar to Microsoft’s when the IE user-
agent string came under fire: Safari is compatible with Mozilla, and Web sites shouldn’t block out Safari
users because they appear to be using an unsupported browser.
Epilogue
Even though user-agent string detection can be highly effective in identifying the browser being used, it
does require some research in order to get accurate results. It is because of this tumultuous history that
many developers favor object/feature detection instead of user-agent string detection. However, user-
agent string detection has enough practical uses to warrant learning how to use it effectively.
233
Browser and Operating System Detection
11_579088 ch08.qxd 3/28/05 11:38 AM Page 233
Free JavaScript Editor
Ajax Editor
©
→