Facebook Twitter Gplus LinkedIn RSS
 
 
Home » Blog » Check the iOS Version with Javascript

Check the iOS Version with Javascript

Published on May 9th, 2012

Sometimes I use my blog for teaching. Sometimes I use my blog for sharing my deep thoughts. Today, I’m using my blog to save some code that I found and altered. Previously I shared how to check whether your device is an iPhone or an iPad, so now I am adding how to check the version number.

1
2
3
4
5
6
7
8
9
function checkVersion() {
    var agent = window.navigator.userAgent,
        start = agent.indexOf( 'OS ' );
 
    if( ( agent.indexOf( 'iPhone' ) > -1 || agent.indexOf( 'iPad' ) > -1 ) && start > -1 ){
        return window.Number( agent.substr( start + 3, 3 ).replace( '_', '.' ) );
    }
    return 0;
}
function checkVersion() {
    var agent = window.navigator.userAgent,
        start = agent.indexOf( 'OS ' );

    if( ( agent.indexOf( 'iPhone' ) > -1 || agent.indexOf( 'iPad' ) > -1 ) && start > -1 ){
        return window.Number( agent.substr( start + 3, 3 ).replace( '_', '.' ) );
    }
    return 0;
}

This function returns the version number from the navigator.userAgent string. All we are doing here is parsing the string for the version number, but this comes in handy when toggling features. I had to use it to shut off the Volume control in my Whipped zApp for pre-4.2 iOS versions.

About the Author: Sprawl

Stephen Russell is a Mobile App developer and all around IT geek that spends his days running data centers and his nights coding. This site is the go to place for all of zSprawl's work and the infamous development blog. In his free time, he enjoys tinkering with web code, playing video games, and otherwise plotting to take over the Internets.

 

Leave a Reply

© 2012 zSprawl's zApps