Operating System Detection

Objective of this OS detection code

The objective of this code is to detect the Operating System of the device.

Lists of supported OS

OS
OS Platform

Windows

  1. Win32

  2. Win64

  3. Windows

  4. WinCE

MacOS

  1. Macintosh

  2. MacIntel

  3. MacPPC

  4. Mac68K

iOS

  1. iPhone

  2. iPad

  3. iPod

Sample Code

getOS Code
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;
}

Sample Code File

Last updated