General Question

Zaku's avatar

How can client-side Javascript determine the iOS version of an iPhone?

Asked by Zaku (30354points) October 4th, 2010

I have a web site which can detect an iPhone using Javascript (navigator.userAgent.match(/iPhone/i)) but JPlayer doesn’t work with iOS3, only iOS4, so I’d like to tell iOS3 users why they can’t use the site, but let iOS4 users use it, instead of having the bug happen to iOS3 users.

I’ve Googled but haven’t seen a way to test for iOS3 vs iOS4. Does anyone happen to know of a way to do this in client-side Javascript?

Observing members: 0 Composing members: 0

4 Answers

ETpro's avatar

This sums up the atate of the art pretty well.

Zaku's avatar

That is very nice, thanks!
Doesn’t seem to distinguish iOS3 from iOS4 though.
I bet there is some difference in the userAgent string… hmm…

jrpowell's avatar

I would use php and do this to grab the browser.

<?php
$browser = $_SERVER[‘HTTP_USER_AGENT’];
?>

From there parse what it returns.

iOS 3.1.3 will return
Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16

iOS 4.0.2 will return
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_2 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A400 Safari/6531.22.7

Just grab the first digit after “iPhone OS” and feed them the appropriate page depending on what os they are using with a if statement. If it was me I wouldn’t use javascript for this. I would handle this server-side.

Zaku's avatar

Thanks @johnpowell! That’s exactly what I needed.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther