04.11.2015 Views

javascript

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: Client Detection<br />

}();<br />

//detection of rendering engines/platforms/devices here<br />

return {<br />

engine: engine,<br />

browser: browser,<br />

system: system<br />

};<br />

The following code detects each of these game systems:<br />

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

system.ps = /playstation/i.test(ua);<br />

For the Wii, a simple test for the string ” Wii ” is enough. The rest of the code will pick up that the<br />

browser is Opera and return the correct version number in client.browser.opera . For the<br />

Playstation, a regular expression is used to test against the user-agent string in a case - insensitive way.<br />

The Complete Script<br />

The complete user - agent detection script, including rendering engines, platforms, Windows operating<br />

systems, mobile devices, and game systems is as follows:<br />

var client = function(){<br />

//rendering engines<br />

var engine = {<br />

ie: 0,<br />

gecko: 0,<br />

webkit: 0,<br />

khtml: 0,<br />

opera: 0,<br />

};<br />

//complete version<br />

ver: null<br />

//browsers<br />

var browser = {<br />

//browsers<br />

ie: 0,<br />

firefox: 0,<br />

safari: 0,<br />

konq: 0,<br />

opera: 0,<br />

chrome: 0,<br />

safari: 0,<br />

//specific version<br />

ver: null<br />

}; (continued)<br />

255

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

Saved successfully!

Ooh no, something went wrong!