7

我想使用 Javascript 检测可视区域的高度。我有这个高度为 550px 的 DIV,我想在浏览器上显示它。但是,此高度可能会导致垂直滚动条出现在某些浏览器上(取决于用户安装了多少工具栏)。在这种情况下,我想检测到这一点,并提醒用户。

我尝试使用document.body.clientHeight,但它似乎不起作用......当我尝试添加新工具栏并刷新页面时,给了我相同的高度。

4

3 回答 3

6

这应该对您有所帮助:http: //www.howtocreate.co.uk/tutorials/javascript/browserwindow

于 2009-06-09T10:42:27.573 回答
4

在 jQuery 中非常简单(并且在不同平台上运行良好):

<html>
    <head>
        <title>Heyo</title>
        <script type="text/javascript" src="jquery.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            $(document).ready(function(){
                alert($(window).height());
                });
        </script>
    </body>
</html>

文档在这里

于 2009-06-09T14:04:18.820 回答
1

YUI 也很容易。

<html>
 <head>
  <title>Heya</title>
  <script type="text/javascript" src="http://yui.yahooapis.com/combo?3.0.0b1/build/yui/yui-min.js"></script>
 </head>
 <body>
   <script type="text/javascript">
    YUI().use('node', function(Y) {
      alert(Y.get(document).get('winHeight'));
    });
   </script>
 </body>
</html>

文档在这里

于 2009-06-28T00:53:08.510 回答