1

Is there a way to obtain an iOS device version (as opposed to OS version) using JavaScript or another browser-based language? For example; iPhone5, iPhone 4S, iPad 3, etc.

I have not been able to locate this information in navigator.userAgent (or any methods of navigator), as it only reports the OS version (and not the device used). For example, an iPhone5 running 6.1.3 has this user-agent:

"Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25"

And an iPhone4 running 6.1.3:

"Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25"

The best I've been able to find is by using the screen.width and screen.height, as this would at least let me differentiate between iPhone5, iPhone4, and previous generations.

Gigazelle
  • 1,424
  • 1
  • 24
  • 34
  • Sorry I cant check this now as I dont currently have an IOS device around me but You could check with other variables in navigator like navigator.appName, navigator.platform, navigator.product, navigator.vendor, etc to see if there is any difference. – Parthik Gosar Apr 09 '13 at 19:25
  • Why do you need to do this? If the browser has the same capabilities, then who cares? And if the browser doesn't have the same capabilities, then you can tell using the standard object detect method in JavaScript. Changing functionality based on the user agent is not best practice. – ErikE Apr 09 '13 at 20:01
  • It is not for changing functionality, it is for a web-based analytics solution. – Gigazelle Apr 09 '13 at 20:23

2 Answers2

2

You can't. You can find iPhone or iPad, and what version of iOS the device is running, but you can't find a model name such as iPhone 4.

Mooseman
  • 18,763
  • 14
  • 70
  • 93
0

This one works for me

var iOS = parseFloat(('' + (/CPU.*OS ([0-9_]{1,5})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0,''])[1]) .replace('undefined', '3_2').replace('_', '.').replace('_', '')) || false;

It return 10.3 on iPhone

vanduc1102
  • 5,769
  • 1
  • 46
  • 43
  • I think in the original post the user was asking about the device version, not the iOS version – Ferie Jun 25 '19 at 09:36