Objective of this OS detection code
The objective of this code is to detect the Operating System of the device.
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;
}