Last active
March 7, 2024 20:57
-
-
Save markhowellsmead/f9cedc275893c0cf5e79c4fc60dec82d to your computer and use it in GitHub Desktop.
Detect a device operating system using JavaScript. Windows OS will be more precisely recognized.
This file contains hidden or 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
if(navigator.appVersion.indexOf("Windows ")!=-1){ | |
os = getWindowsOS(); | |
}else{ | |
os = navigator.platform; | |
} | |
function getWindowsOS(){ | |
// http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#PltToken | |
if(navigator.appVersion.indexOf("Windows NT 10.")!=-1){ | |
return 'Windows 10'; | |
}else if(navigator.appVersion.indexOf("Windows NT 6.3")!=-1){ | |
return "Windows 8.1"; | |
}else if(navigator.appVersion.indexOf("Windows NT 6.2")!=-1){ | |
return "Windows 8"; | |
}else if(navigator.appVersion.indexOf("Windows NT 6.1")!=-1){ | |
return "Windows 7"; | |
}else if(navigator.appVersion.indexOf("Windows NT 6.0")!=-1){ | |
return "Windows Vista"; | |
}else if(navigator.appVersion.indexOf("Windows NT 5.2")!=-1){ | |
return "Windows Server 2003; Windows XP x64 Edition"; | |
}else if(navigator.appVersion.indexOf("Windows NT 5.1")!=-1){ | |
return "Windows XP"; | |
}else if(navigator.appVersion.indexOf("Windows NT 5.01")!=-1){ | |
return "Windows 2000, Service Pack 1 (SP1)"; | |
}else if(navigator.appVersion.indexOf("Windows NT 5.0")!=-1){ | |
return "Windows 2000"; | |
}else if(navigator.appVersion.indexOf("Windows NT 4.0")!=-1){ | |
return "Windows NT 4.0"; | |
}else if(navigator.appVersion.indexOf("Windows 98; Win 9x 4.90")!=-1){ | |
return "Windows Millennium Edition (Windows Me)"; | |
}else if(navigator.appVersion.indexOf("Windows 98")!=-1){ | |
return "Windows 98"; | |
}else if(navigator.appVersion.indexOf("Windows 95")!=-1){ | |
return "Windows 95"; | |
}else if(navigator.appVersion.indexOf("Windows CE")!=-1){ | |
return "Windows CE"; | |
}else{ | |
return "Windows OS, Version nicht bekannt"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment