Created
July 15, 2014 13:47
-
-
Save nufaylr/56a2255e5e31e708d45c to your computer and use it in GitHub Desktop.
get mobile OS and version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getOSInfo(){ | |
| var userOS; | |
| var userOSver; | |
| 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'; | |
| } | |
| return { | |
| os : userOS, | |
| version : userOSver | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment