Last active
September 24, 2015 12:01
-
-
Save oti/58f38b1b87813613c69f to your computer and use it in GitHub Desktop.
sp-version.js
This file contains 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
var ua = navigator.userAgent.toLowerCase(); | |
var device = {}; | |
function _getVersion(ua, token, delimiter) { | |
var verArr = ua.split(token)[1].trim().split(/[^\w\.]/)[0].split(delimiter) | |
return { | |
major: parseInt(verArr[0], 10) || 0, | |
minor: parseInt(verArr[1], 10) || 0, | |
patch: parseInt(verArr[2], 10) || 0 | |
} | |
} | |
if(/iphone/.test(ua)) { | |
device.name = 'iphone'; | |
device.version = _getVersion(ua, 'iphone os', '_'); | |
} else if(/android/.test(ua)){ | |
device.name = 'android'; | |
device.version = _getVersion(ua, 'android', '.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super Awesome Ultra Amazing Thanks https://github.com/uupaa/UserAgent.js/blob/392b311db878a40db5b0056de86a2eb2b8883904/lib/UserAgent.js#L206