<script type="text/javascript">
var winWidth = 0;
var winHeight = 0;function findDimensions() 
{winWidth = body.clientWidth;winHeight = body.clientHeight;
alert(winHeight);
alert(winWidth);}findDimensions();
this.onresize=findDimensions;</script>

解决方案 »

  1.   

    winWidth = document.body.clientWidth;winHeight = document.body.clientHeight;
      

  2.   

    body不能这么引用。并且直接这么写的话也不行,运行代码时body还没构造出来呢,应该用onload。
    <html>
    <head>
    <title>T</title>
    <script type="text/javascript">
    var $=document.getElementById;var winWidth = 0;
    var winHeight = 0;function findDimensions() 
    {winWidth = $("main").clientWidth;winHeight = $("main").clientHeight;
    alert(winHeight);
    alert(winWidth);}window.onload=findDimensions;
    this.onresize=findDimensions;</script>
    </head>
    <body id="main">
    safadsfjaa
    asdfl
    adskf
    </body>
    </html>
      

  3.   

    <html>
    <head>
    </head>
    <body>
    <script type='text/javascript'>var winWidth = 0;
    var winHeight = 0;function findDimensions() 
    {winWidth = document.body.clientWidth;winHeight = document.body.clientHeight;
    alert(winHeight);
    alert(winWidth);}findDimensions();
    this.onresize=findDimensions;
    </script>
    </body>
    </html>