JavaScript gets user Client operating system version _javascript tips

Source: Internet
Author: User
In the afternoon to visit the user site, the feeling that the problem is really strange, and finally found that the computer is win 2000 of the operating system, feel the crux of the problem may be here, the internet Google, found that the original media Player 11 does not support the Win2000 system, Users are required to download the player version for the user's operating system version, so that Win2000 users can download media Player 9.
Well, the problem is found, and solving the problem is a simple matter.
The following is mainly about how to use JavaScript to determine the user's operating system and version.
Key parts:
Window.navigator.userAgent: User browser, operating system and other information, corresponding to the HTML request file header User-agent part.
Code section:
<script language= "JavaScript" >
var ua = window.navigator.userAgent;
var osversion = Ua.split (";") [2];
var OsV = osversion.substr (osversion.length-3,3);
Switch (OsV)
{
Case "5.0":
document.write ("Win2000");
Break
Case "5.1":
document.write ("WinXP");
Break
Case "5.2":
document.write ("Win2003");
Break
Default
document.write ("others");
Break
}
</script>
Note:
Window.navigator.userAgent several values:
1) winxp+ie7:mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; CIBA. NET CLR 2.0.50727;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729)
2) winxp+ff3.0:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.0.10) gecko/2009042316 firefox/3.0.10 (. NET CLR 3.5.30729)
3) win2000+ie6:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
4) win2000+ff3.1:mozilla/5.0 (Windows; U Windows NT 5.0; ZH-CN; RV:1.9.1B2) gecko/20081201 firefox/3.1b2
The above values are for reference only, in order to understand the code, specific values please specific test, do not book as much as the letter, the letter is not as good as the letter they do, hehe
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.