04.11.2015 Views

javascript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Client Detection<br />

Note that even though the Nokia Nseries phones report ” Safari ” in the user - agent string, the browser<br />

is not actually Safari though it is WebKit - based. A simple check for ” NokiaN ” in the user - agent string, as<br />

shown here, is sufficient to detect this series of phones:<br />

system.nokiaN = ua.indexOf(“NokiaN”) > -1;<br />

With this device information, it ’ s possible to figure out how the user is accessing a page with WebKit by<br />

using code such as this:<br />

if (client.engine.webkit){<br />

if (client.system.macMobile){<br />

//mac mobile stuff<br />

} else if (client.nokiaN){<br />

//nokia stuff<br />

}<br />

}<br />

The last major mobile - device platform is Windows Mobile (also called Windows CE), which is available<br />

on both Pocket PCs and smartphones. Since these devices are technically a Windows platform, the<br />

Windows platform and operating system will return correct values. For Windows Mobile 5.0 and earlier,<br />

the user - agent strings for these two devices were very similar, such as the following:<br />

Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)<br />

Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Smartphone; 176x220)<br />

The first of these is mobile Internet Explorer 4.01 on the Pocket PC, and the second one is the same<br />

browser on a smartphone. When the Windows operating system detection script is run against either of<br />

these strings, client.win gets filled with ” CE ” , so detection for Windows Mobile can be done using this<br />

value:<br />

system.winMobile = (client.win == “CE”);<br />

It ’ s not advisable to test for ” PPC ” or ” Smartphone ” in the string, because these tokens have been<br />

removed in browsers on Windows Mobile later than 5.0. Oftentimes, simply knowing that the device is<br />

using Windows Mobile is enough.<br />

Identifying Game Systems<br />

Another new area in which web browsers have become increasingly popular is on video game systems.<br />

Both the Nintendo Wii and Playstation 3 have web browsers either built in or available for download.<br />

The Wii browser is actually a custom version of Opera, designed specifically for use with the Wii<br />

remote. The Playstation browser is custom and is not based on any of the rendering engines previously<br />

mentioned. The user - agent strings for these browsers are as follows:<br />

Opera/9.10 (Nintendo Wii;U; ; 1621; en)<br />

Mozilla/5.0 (PLAYSTATION 3; 2.00)<br />

The first user - agent string is Opera running on the Wii. It stays true to the original Opera user - agent<br />

string (keep in mind that Opera on the Wii does not have identity - masking capabilities). The<br />

second string is from a Playstation 3, which reports itself as Mozilla 5.0 for compatibility but doesn ’ t give<br />

253

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!