Use JavaScript to obtain the operating system version of the client.

Source: Internet
Author: User

In the afternoon, I went to the user's site and felt that the problem was indeed quite strange. Finally, I found that the computer with the problem was Windows 2000, and I felt that the problem was probably caused by google surfing the Internet, it is found that Media Player 11 does not support the Win2000 system. You need to determine the version of the Player you want to download based on your operating system, so that Win2000 users can download Media Player 9.
Well, the cause of the problem is found. Solving the problem is very simple.
The following describes how to use JavaScript to determine the user's operating system and version.
Key part:
Window. navigator. userAgent: information such as the User's browser and operating system, corresponding to the User-Agent section of the HTML request file header.
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 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.20.6.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, so that you can understand the code. Test the specific values. Believe in books as much as you do, and believe in what others say as well as your own.
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.