JavaScript 获取用户客户端操作系统版本
JavaScript如何判断用户操作系统及版本。
关键部分:
window.navigator.userAgent :用户浏览器、操作系统等信息,对应HTML请求文件头User-Agent部分。
代码部分:
<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>
备注:
window.navigator.userAgent几种值:
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
关键部分:
window.navigator.userAgent :用户浏览器、操作系统等信息,对应HTML请求文件头User-Agent部分。
代码部分:
<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>
备注:
window.navigator.userAgent几种值:
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