Skip to content

Instantly share code, notes, and snippets.

@ngoclt
Created June 2, 2012 08:15
Show Gist options
  • Save ngoclt/2857281 to your computer and use it in GitHub Desktop.
Save ngoclt/2857281 to your computer and use it in GitHub Desktop.
Check iOS version with Javascript
checkVersion = function () {
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;
}
@drix
Copy link

drix commented Apr 19, 2023

let checkVersion = () => /(iPhone|iPad) OS ([1-9]*)/g.exec(window.navigator.userAgent)?.[2] || 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment