2009-06-09 6 views
6

자바 스크립트를 사용하여 가시 영역의 높이를 감지하고 싶습니다. 이 DIV는 브라우저에 표시하려는 높이 550px입니다. 그러나이 높이로 인해 사용자가 설치 한 도구 막대의 수에 따라 일부 브라우저에는 세로 스크롤 막대가 나타날 수 있습니다. 이 경우 나는 그것을 감지하고 사용자에게 경고하고 싶다.자바 스크립트를 사용하여보기 영역의 높이 감지

document.body.clientHeight을 사용해 보았지만 작동하지 않는 것처럼 보였습니다 ... 새 툴바를 추가하고 페이지를 새로 고쳤을 때 같은 높이가되었습니다.

답변

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> 

Documentation here

+3

-1 : 이것은 창 높이가 아닌 전체 내용의 높이입니다. (예 : 내 콘텐츠는 1450px이지만 내 창은 641px입니다. $ (window) .height()는 1450을 반환합니다. –

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> 
하지 않은에서 라이브러리 솔루션

Documentation here

관련 문제