2009-12-01 10 views

cevap

21

Yöntemi görmek için bu blog post numaralı sayfaya göz atabilirsiniz.

ve kısa in içinde

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); 
} 

da js çerçeve (jQuery, dahili, prototip) çoğu bu (IMHO) yapmak için bir işlev temin edebileceğine işaret gerektiğini kodu verir. jQuery

: o zaman

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

, bu çerçevede mümkündür? –

+0

@ BahaiResearch.com: Düzenledim. – RageZ

+7

-1 jQuery, görünür alanın yüksekliğini ve genişliğini döndürmez; kullanıcının geçebileceği yüksekliğini ve genişliğini döndürür. – schlingel

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

:

document.getElementById('THE_HTML').clientHeight; 

Test ve IE8 ve FF3.6 altında çalışan ... Pencere özelliği, iç yüksekliği nesneleri

4

Kullanım/width, sadece web sayfasındaki içeriğin boyutlarını bulmak için. Bu kaydırma çubuklarını içerir. İşte görsel bir açıklama ->http://goo.gl/L0cBLA.

Yükseklik:

window.innerHeight 

Genişliği: jQuery kullanmak

window.innerWidth