Is there any way (using Javascript, PHP, etc) to detect the version of an iOS page, when the page is visited on MobileSafari?
Here's a bit of JS to determine iOS and Android OS version.
Tested with actual user agent strings for iOS 4.3 to 6.0.1, and Android 2.3.4 to 4.2
var userOS; // will either be iOS, Android or unknown
var userOSver; // this is a string, use Number(userOSver) to convert
function getOS( )
{
var ua = navigator.userAgent;
var uaindex;
// determine OS
if ( ua.match(/iPad/i) || ua.match(/iPhone/i) )
{
userOS = 'iOS';
uaindex = ua.indexOf( 'OS ' );
}
else if ( ua.match(/Android/i) )
{
userOS = 'Android';
uaindex = ua.indexOf( 'Android ' );
}
else
{
userOS = 'unknown';
}
// determine version
if ( userOS === 'iOS' && uaindex > -1 )
{
userOSver = ua.substr( uaindex + 3, 3 ).replace( '_', '.' );
}
else if ( userOS === 'Android' && uaindex > -1 )
{
userOSver = ua.substr( uaindex + 8, 3 );
}
else
{
userOSver = 'unknown';
}
}
Then to detect a specific version and higher, try:
if ( userOS === 'iOS' && Number( userOSver.charAt(0) ) >= 5 ) { ... }
You should be able to parse the UserAgent String for it.
Here's an example User Agent String that declares the OS to be 4.3.1
Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With