Created
October 24, 2017 10:50
-
-
Save osbre/326785f463fccf12ca4e723bc1a0c613 to your computer and use it in GitHub Desktop.
Function for get user operating-system name
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
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