看不出是什么问题,我是这样写的:function checkOS () {
//转换成小写以方便运算
var userAgent = navigator.userAgent.toLowerCase();
var osStr = ""; this.win31 = (userAgent.indexOf("windows 3.1")!=-1) || (userAgent.indexOf("win16")!=-1) || (userAgent.indexOf("windows 16-bit")!=-1);
osStr = (this.win31) ? osStr+"win31" : osStr+"";
this.win95 = (userAgent.indexOf("win95")!=-1) || (userAgent.indexOf("windows 95")!=-1);
osStr = (this.win95) ? osStr+"win95" : osStr+"";
this.win98 = (userAgent.indexOf("win98")!=-1) || (userAgent.indexOf("windows 98")!=-1);
osStr = (this.win98) ? osStr+"win98" : osStr+"";
this.winNT = ((userAgent.indexOf("winnt")!=-1) || (userAgent.indexOf("windows nt")!=-1)) && (userAgent.indexOf("windows nt 5.0")==-1);
osStr = (this.winNT) ? osStr+"winNT" : osStr+"";
this.win2000 = userAgent.indexOf("windows nt 5.0") != -1;
osStr = (this.win2000) ? osStr+"win2000" : osStr+"";
this.winME = userAgent.indexOf("win 9x 4.90") != -1;
osStr = (this.winME) ? osStr+"winME" : osStr+"";
this.winXP = userAgent.indexOf("windows nt 5.1") != -1;
osStr = (this.winXP) ? osStr+"winXP" : osStr+""; this.os2 = (userAgent.indexOf("os/2")!=-1) || (userAgent.indexOf("ibm-webexplorer")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1);
osStr = (this.os2) ? osStr+"os" : osStr+""; this.mac = userAgent.indexOf("mac") != -1;
osStr = (this.mac) ? osStr+"mac" : osStr+""; this.linux = userAgent.indexOf("linux") != -1;
osStr = (this.linux) ? osStr+"linux" : osStr+""; this.osStr = osStr;
}
var clientOS = new checkOS();
document.write("您的操作系统是:" + clientOS.osStr);
//转换成小写以方便运算
var userAgent = navigator.userAgent.toLowerCase();
var osStr = ""; this.win31 = (userAgent.indexOf("windows 3.1")!=-1) || (userAgent.indexOf("win16")!=-1) || (userAgent.indexOf("windows 16-bit")!=-1);
osStr = (this.win31) ? osStr+"win31" : osStr+"";
this.win95 = (userAgent.indexOf("win95")!=-1) || (userAgent.indexOf("windows 95")!=-1);
osStr = (this.win95) ? osStr+"win95" : osStr+"";
this.win98 = (userAgent.indexOf("win98")!=-1) || (userAgent.indexOf("windows 98")!=-1);
osStr = (this.win98) ? osStr+"win98" : osStr+"";
this.winNT = ((userAgent.indexOf("winnt")!=-1) || (userAgent.indexOf("windows nt")!=-1)) && (userAgent.indexOf("windows nt 5.0")==-1);
osStr = (this.winNT) ? osStr+"winNT" : osStr+"";
this.win2000 = userAgent.indexOf("windows nt 5.0") != -1;
osStr = (this.win2000) ? osStr+"win2000" : osStr+"";
this.winME = userAgent.indexOf("win 9x 4.90") != -1;
osStr = (this.winME) ? osStr+"winME" : osStr+"";
this.winXP = userAgent.indexOf("windows nt 5.1") != -1;
osStr = (this.winXP) ? osStr+"winXP" : osStr+""; this.os2 = (userAgent.indexOf("os/2")!=-1) || (userAgent.indexOf("ibm-webexplorer")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1);
osStr = (this.os2) ? osStr+"os" : osStr+""; this.mac = userAgent.indexOf("mac") != -1;
osStr = (this.mac) ? osStr+"mac" : osStr+""; this.linux = userAgent.indexOf("linux") != -1;
osStr = (this.linux) ? osStr+"linux" : osStr+""; this.osStr = osStr;
}
var clientOS = new checkOS();
document.write("您的操作系统是:" + clientOS.osStr);
解决方案 »
- 如何获取到ext buttons配置里的某个按钮?
- Js 或者 Jquery 实现在Repeater中操作 Checkbox的问题
- 在Dtree中添加了判断为什么就一直循环了?
- 关于Ajax里跳转页面的问题,请各位高手帮忙
- 求一段javascript程序,实现图片的交替显示
- 我是新手,怎样通过一个js函数获取一个jsp页面输入的值?
- 我用window.showModalDialog打开一个子窗口,为什么在提交的时候,会出现一个要求刷新的页面...
- 请问有没有办法写一个js,用来清除在IE中不小心保存的记忆密码,谢谢
- 如何将ie6的图像工具栏转换成页面按纽实现,
- 如何在页面中单击左键能弹出右键的快捷菜单
- 如何判断当前表格失去焦点?或是当前的焦点?
- js中,如何释放内存
for(i in mxh)
{
if(mxh[i]==0)
continue;
else
{
for (var j=0;j<os.length;j++){
if(mxh[i]==j)
document.write("您的操作系统:" + os[j] + "<br>");
} }
}
function Is()
{ var agt=navigator.userAgent.toLowerCase(); // *** 使用平台检测 ***
this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)) ? 1 : 0 ;
this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1)) ? 2 : 0 ;
this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt 4.0")!=-1)) ? 3: 0 ;
this.winme = ((agt.indexOf("win 9x 4.90")!=-1)) ? 4 : 0 ;
this.win2k = ((agt.indexOf("windows nt 5.0")!=-1)) ? 5 : 0 ;
this.winxp = ((agt.indexOf("windows nt 5.1")!=-1)) ? 6 : 0 ;
this.os2 = ((agt.indexOf("os/2")!=-1) ||
(navigator.appVersion.indexOf("OS/2")!=-1) ||
(agt.indexOf("ibm-webexplorer")!=-1)) ? 7 : 0 ; this.mac = (agt.indexOf("mac")!=-1) ? 8 : 0 ; if (this.mac && this.ie5up) this.js = 1.4;
this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) ||
(agt.indexOf("68000")!=-1))) ? 9 : 0 ;
this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) ||
(agt.indexOf("powerpc")!=-1))) ? 10 : 0 ;
}
var os=new Array(10); os[1]="Windows 95"
os[2]="Windows 98"
os[3]="Windows NT"
os[4]="Windows ME"
os[5]="Windows 2000"
os[6]="Windows XP"
os[7]="os2"
os[8]="mac"
os[9]="mac68k" var mxh=new Is();
var j=1;
for(i in mxh)
{
if(mxh[i]!=0) document.write("您的操作系统:" + os[j] + "<br>");
j++;
}
</script>
function Is()
{ var agt=navigator.userAgent.toLowerCase(); // *** 使用平台检测 ***
this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)) ? 1 : 0 ;
this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1)) ? 2 : 0 ;
this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt 4.0")!=-1)) ? 3: 0 ;
this.winme = ((agt.indexOf("win 9x 4.90")!=-1)) ? 4 : 0 ;
this.win2k = ((agt.indexOf("windows nt 5.0")!=-1)) ? 5 : 0 ;
this.winxp = ((agt.indexOf("windows nt 5.1")!=-1)) ? 6 : 0 ;
this.os2 = ((agt.indexOf("os/2")!=-1) ||
(navigator.appVersion.indexOf("OS/2")!=-1) ||
(agt.indexOf("ibm-webexplorer")!=-1)) ? 7 : 0 ; this.mac = (agt.indexOf("mac")!=-1) ? 8 : 0 ; if (this.mac && this.ie5up) this.js = 1.4;
this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) ||
(agt.indexOf("68000")!=-1))) ? 9 : 0 ;
this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) ||
(agt.indexOf("powerpc")!=-1))) ? 10 : 0 ;
this.platform=0; var os=new Array(10); os[1]="Windows 95"
os[2]="Windows 98"
os[3]="Windows NT"
os[4]="Windows ME"
os[5]="Windows 2000"
os[6]="Windows XP"
os[7]="os2"
os[8]="mac"
os[9]="mac68k" var j=1;
for(obj in this)
{
if(this[obj]!=0)
{
this.platform=os[j];
break;
}
j++;
}
}
var mxh=new Is();
alert(mxh.platform);
</script>