Skip to content

Instantly share code, notes, and snippets.

@osbre
Created October 24, 2017 10:50
Show Gist options
  • Save osbre/326785f463fccf12ca4e723bc1a0c613 to your computer and use it in GitHub Desktop.
Save osbre/326785f463fccf12ca4e723bc1a0c613 to your computer and use it in GitHub Desktop.
Function for get user operating-system name
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (macosPlatforms.indexOf(platform) !== -1) {
os = 'Mac OS';
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = 'Windows';
} else if (/Android/.test(userAgent)) {
os = 'Android';
} else if (!os && /Linux/.test(platform)) {
os = 'Linux';
}
return os;
}
// exemple:
//alert(getOS());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment