IOS5 detection in mobile Safari (javascript recommended)

The new fixed positioning introduced in iOS5 has distorted my webapp, and I need a way to detect iOS5 users.

How can I detect iOS5? What is a browser agent string? Preferred JavaScript. Thanks!

+7
source share
4 answers

From a SO question: what is an iOS 5 user agent string:

iPhone:

Mozilla / 5.0 (iPhone, iPhone 5 OS, like Mac OS X) AppleWebKit / 534.46 (KHTML, e.g. Gecko) Version /5.1 Mobile / 9A334 Safari / 7534.48.3

IPad:

Mozilla / 5.0 (iPad, CPU OS 5_0, like Mac OS X) AppleWebKit / 534.46 (KHTML, e.g. Gecko) Version /5.1 Mobile / 9A334 Safari / 7534.48.3

And here is a way to check ios 5.x in javascript:

<script type="text/javascript"> if (navigator.userAgent.match(/OS 5(_\d)+ like Mac OS X/i)) // this helps detect minor versions such as 5_0_1 document.write("You have iOS 5! Aren't you special!"); </script> 
+15
source

You need to consider "CPU OS 5_0" and "CPU iPhone OS 5_0", a rude and dirty regex:

 <script type="text/javascript"> if (navigator.userAgent.match(/(iPad|iPhone);.*CPU.*OS 5_\d/i)) { alert("On iOS 5") } else { alert("Not on iOS 5"); //could be either 4- or 6+ } </script> 
+2
source

You can use Modernizr and detect Website Workers because they were not available before iOS 5. You should still exclude Android, since Android 2.0+ supports them. This will give you cutting-edge iOS6 compatibility that you are not going to receive with any of the user agent analyzes already provided.

+2
source

I developed the chown answer a bit further, with validation on any iOS5 device, be it 5 or 5.0.1 or any later versions:

 var ios5 = navigator.userAgent.match(/OS 5_[0-9_]+ like Mac OS X/i) != null; if(ios5) { // Now you can do specific stuff for devices on any version of iOS5 } 
+2
source

All Articles