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.