Detecting iPhone/iPad, OS version and more.

Lets take and example of some user agent:

Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; es-es) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405
Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; es-es) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B405 Safari/531.21.10
Mozilla/5.0 (iPad; U; CPU OS 3_2_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B500 Safari/531.21.10
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16

--X----X----X----X----X----X----X----X----X----X--

For both BlackBerry and iOS Device detect : /\([a-z]*;/i
O/P : "(iPad;", "(iPhone;", "(BlackBerry;"
Comment : just remove the "("  & ";" from the output and use it.

For MAC OS Detect : /\d_\d_?\d?/
O/P : "3_2_1" , "3_2"

For Version : /version\/\d.\d\S*/i
O/P : "Version/4.0.4", "Version/4.0", "Version/6.0.0.141"

For Browser Version: /safari\/\d.\d\S*/i
O/P : "Safari/531.21.10", "Safari/528.16", "Safari/534.1+"

For Language : /[a-z]{2}(-[a-z]{2})/i
O/P : en-es, en-us

For more help: http://rubular.com/

Comments

Anonymous said…
What's up, its nice paragraph regarding media print, we all be aware of media is a great source of data.

Here is my site http://ultrasoundtechnologist.bravesites.com

Popular posts from this blog

Leap Year Calculator

PDF form validation using javascript

CSS Mouse Cursors and Custom Cursors