Created
August 23, 2012 07:31
-
-
Save hkulekci/3433850 to your computer and use it in GitHub Desktop.
Detect Operating System with Javascript
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
// This script sets OSName variable as follows: | |
// "Windows" for all versions of Windows | |
// "MacOS" for all versions of Macintosh OS | |
// "Linux" for all versions of Linux | |
// "UNIX" for all other UNIX flavors | |
// "Unknown OS" indicates failure to detect the OS | |
var OSName="Unknown OS"; | |
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; | |
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; | |
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; | |
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; | |
document.write('Your OS: '+OSName); |
@SylarRuby could you please add a sample to your comment? We can change the script with your sample. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. It's 2021. Maybe an update to
navigator.userAgent...
?appVersion
is deprecated.