转载-js判断操作系统
2009-11-06 14:05
出处已经不能明确。
window.navigator.userAgent :用户浏览器、操作系统等信息,对应HTML请求文件头User-Agent的部分。
代码如下:
<script type="text/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 type="text/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