2009-12-01 14 views

答えて

21

この方法を見るにはblog postをご覧ください。

と短い中でもJSフレームワーク(jqueryの、内線、試作品)のほとんどは(私見)ことを行うための機能を提供することに注意する必要がそのコードに

function alertSize() { 
    var myWidth = 0, myHeight = 0; 
    if(typeof(window.innerWidth) == 'number') { 
     // Non-IE 
     myWidth = window.innerWidth; 
     myHeight = window.innerHeight; 
    } 
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { 
     // IE 6+ in 'standards compliant mode' 
     myWidth = document.documentElement.clientWidth; 
     myHeight = document.documentElement.clientHeight; 
    } 
    else if(document.body && (document.body.clientWidth || document.body.clientHeight)) { 
     // IE 4 compatible 
     myWidth = document.body.clientWidth; 
     myHeight = document.body.clientHeight; 
    } 

    window.alert('Width = ' + myWidth); 
    window.alert('Height = ' + myHeight); 
} 

を与えます。 jQueryので

:その後、

$(window).width(); 
$(window).height(); 
+0

私はjQueryのを使用するが、これはこの枠組みの中で可能ですか? –

+0

@ BahaiResearch.com:私は編集しました。 – RageZ

+7

-1 jQueryは可視領域の高さと幅を返しません。ユーザーがスクロールできる高さと幅を返します。 – schlingel

1
<html id="THE_HTML"> 
<!-- all your stuff... --> 
</html> 

document.getElementById('THE_HTML').clientHeight; 

検査済みとIE8とFF3.6の下で働いて...ウィンドウは、プロパティ、内側の高さをオブジェクト

4

使用/ widthを使用して、Webページ上のコンテンツのサイズを検索します。これにはスクロールバーが含まれます。ここに視覚的な説明 - >http://goo.gl/L0cBLAがあります。

身長:

window.innerHeight 

幅:

window.innerWidth 
関連する問題