Skip to content

Instantly share code, notes, and snippets.

@oti
Last active September 24, 2015 12:01
Show Gist options
  • Save oti/58f38b1b87813613c69f to your computer and use it in GitHub Desktop.
Save oti/58f38b1b87813613c69f to your computer and use it in GitHub Desktop.
sp-version.js
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', '.');
}
@oti
Copy link
Author

oti commented Sep 24, 2015

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