Skip to content

Instantly share code, notes, and snippets.

@hostedpixel
Created August 30, 2017 16:19
Show Gist options
  • Save hostedpixel/d3c34bba2fef37a4da307947f1dad6de to your computer and use it in GitHub Desktop.
Save hostedpixel/d3c34bba2fef37a4da307947f1dad6de to your computer and use it in GitHub Desktop.
Detecting IOS 7 Version
// Detecting IOS 7
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;
console.log(ua);
// 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';
}
if ( userOS === 'iOS' && Number( userOSver.charAt(0) ) >= 7 ) { console.log('Version 7 or hight');
} else { 'Not right versin';
}
}
getOS();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment