This article describes the method of obtaining client operating system types by js. Share it for your reference, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>jsJudge client operating system type</title></head><body><script language="javascript">function detectOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows"); var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel"); if (isMac) return "MacOS"; var isUnix = (navigator.platform == "X11") && !isWin && !isMac; if (isUnix) return "Unix"; var isLinux = (String(navigator.platform).indexOf("Linux") > -1); if (isLinux) return "Linux"; if (isWin) { var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1; if (isWin2K) return "Windows2000"; var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1; if (isWinXP) return "Windows XP"; var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows NT 5.2") > -1; if (isWin2003) return "Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1; if (isWinVista) return "Windows Vista"; var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1; if (isWin7) return "Windows7"; } return "other";}document.writeln("Your operating system is: " + detectOS());</script></body></html>PS: By the way, the IP home query tool of this website’s online tool also uses the above method to judge the user’s operating system type. as follows:
Online query tool for IP address home location:
http://tools.VeVB.COM/aideddesign/ipcha
By the way, I would like to recommend several more practical JS online formatting tools for you. I believe that they will be used frequently in future development:
C language style/HTML/CSS/json code formatting and beautification tools:
http://tools.VeVB.COM/code/ccode_html_css_json
Online JavaScript code beautification and formatting tools:
http://tools.VeVB.COM/code/js
JavaScript code beautification/compression/formatting/encryption tools:
http://tools.VeVB.COM/code/jscompress
Online JSON code verification, inspection, beautification and formatting tools:
http://tools.VeVB.COM/code/json
json code online formatting/beautification/compression/editing/converting tools:
http://tools.VeVB.COM/code/jsoncodeformat
For more information about JavaScript, please check this site's special topics: "Summary of Ajax Operation Skills in JavaScript", "Summary of JSON Operation Skills in JavaScript", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm techniques", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.