大家好,我刚学习 JavaScript  ,今天遇到一个问题向请教大家,在网上搜索了好多,都不能解决问题,恳请大家帮个忙。
先行谢过啦。问题:点击一个链接,触发一个事件,由这个事件来判断用户分辨率,并返回分辨率值的提示,再进行相应的跳转操作。文件:a.html ;  b.html ; index.html 代码:在index.html中:<html>
<head>
<title>主页</title>
<script type="text/javascript" language="javascript">
         var x = screen.width;
         var y = screen.height;
function screen(){
                  if(x < 1280){
                       alert('您显示器的分辨率为:\n' + x + '×' + y + ' 像素');
                       document.getElementById("goTo").href="a.html";
                   }
else{
                       document.getElementById("goTo").href="b.html";
                   }
}</script>
</head>
<body>
<a href="a.html" id="goTo"><img src="" onclick="screen()" /></a>
</body>
</html>
在上面的代码中,得不得  x  y 的值。请问,如何修改才能实现上面的效果呢?谢谢!!!!!!!!!!!!在线等。。

解决方案 »

  1.   

    显示器是
    window.screen.availHeight //显示器高度,windows里不包括任务栏高度
    window.screen.availWidth //显示器宽度
    window.screen.colorDepth //显示色深
      

  2.   

    alert('您显示器的分辨率为:\n' + x + '×' + y + ' 像素');
                          
    输出的结果是:您显示器的分辨率为:undefined x undefined
      

  3.   

    为什么得不到  值呢?
    如果把方法screen() 直接写成:function(){
       var x = screen.width;
       var y = screen.height;
       alert('您显示器的分辨率为:\n' + x + '×' + y + ' 像素'); 
    }当下面调用这个方法后,运行显示结果为:
    您显示器的分辨率为:undefined x undefined 
      

  4.   

    <html>
    <head>
    <title>主页</title>
    <script type="text/javascript" language="javascript">
    function screen(){
    alert('您显示器的分辨率为:\n' + screen.width + '×' + screen.height + ' 像素');
    }
    </script>
    </head>
    <body>
    <input type="button" value="获得分辨率" onclick="screen()" /></a>
    </body>
    </html>
      

  5.   

    alert('您显示器的分辨率为:\n' + window.screen.width + '×' + window.screen.height + ' 像素');
    写全试试,完全没问题啊
      

  6.   

    发现问题了:方法名screen()为关键字。。弄了很长时间。还是感觉楼上几位的回答
      

  7.   

    今天我也发现了这个问题
      var width=screen.width;
      var height=screen.heiht;
      document.write(width+"*"+height);我这样写,,为什么显示
    1440*undefined 
    我也是很菜的,,见笑了~~
      

  8.   

    每种分辨率开发一个网页,成本也忒高了点..
    好好用css部部局不就解决了么..