Welcome to WebmasterWorld Guest from

Forum Moderators: travelin cat

Message Too Old, No Replies

Ad code which recognises Mac OS

7:40 am on Oct 20, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 25, 2005
posts: 80
votes: 0

We're looking for code which will enable recognise a Mac operating system (presumably via the GET + browser headers) and then enable the display of a certain piece of code as opposed to the other(s).

We've not had any luck finding working examples via google, does anyone have a suggestion?


8:22 am on Oct 20, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 7, 2003
votes: 0

The user agent string for popular browsers should be easily obtained and you can then deliver different content based on that depending on OS.

Check your logs for the user agent strings.

Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"

That's a windows based firefox (tainted by the .net plugin)

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/20090824 Firefox/3.5.3
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en-US; rv: Gecko/20090824 Firefox/3.5.3

That's the same version of Firefox on an intel mac and PowerPC mac respectively.

Safari windows:
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3
Safari mac:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9

Opera 10 windows:
Opera/9.80 (Windows NT 5.1; U; en) Presto/2.2.15 Version/10.00
Opera 10 mac:
Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00

Chrome on windows:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/ Safari/532.0
Chromium on mac:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Chrome/ Safari/532.2

From the sample above it feels safe to say that if you find
"Mozilla/5.0 (Macintosh;" at the beginning of the user agent string that you're dealing with a mac user. Since that excludes browsers that do not claim to be netscape (a trend started by MSFT during the browser wars),

Just match on "(Macintosh;" being part of the user agent string.