2011-07-07 12 views
1

私は、ページ全体のマスクとしてdivを設定するために使用しています。jquery document width

$(document).width(); 

しかし、これはIEとFirefoxの動作が異なります。 IEでは796を返しますが、Firefoxでは789を返します。 マスクの幅を$(document).width();とすると、

firefoxでは、マスクは画面にフィットします。 しかしIEでは、追加のスクロールバーが下に表示されます。

マスクを画面に合わせたい。これを手伝ってください。

window.width()と100%は、ウィンドウのサイズを変更すると助けになりません。私は場所のcozで$( '体')を使用することはできません、私は同じ方法で身長を計算する必要があります。

ありがとうございます。

答えて

2

これはliterately試行錯誤の日であるともないjqueryのは、それを適切に報告するためpureJSを使用して、すべての世界を

を検索!ブラウザを識別するためにはjqueryが必要です。私はこれをiframeで体を測定するために使用しました。クロスドメイン通信のスクロールバーを避けるために、少し調整することができました。しかしコアある

if ($.browser.msie) { 
     var thisH = thisFrame.scrollHeight;  
     var thisW = thisFrame.scrollWidth;  
     }  
    else if ($.browser.opera) 
     { 
     var thisW = thisFrame.scrollWidth; 
     if (iframe.clientWidth > thisW) { 
      thisW = 660; //These are custom- you can ignore it 
     } 

     var thisH = thisFrame.scrollHeight; 
     if (iframe.clientHeight > thisH) { 
      thisH = 550; //These are custom- you can ignore it 
       } 
     } 
    //All other clients 
    else     
     {   
     var thisW = thisFrame.scrollWidth; 
     if (iframe.clientWidth > thisW) { 
     thisW = 660; //These are custom- you can ignore it 
     } 

     var thisH = $(thisFrame).height(); 
      if (iframe.clientHeight > thisH) { 
      thisH = 550; //These are custom- you can ignore it 
      } 
     }  
0

http://www.javascripter.net/faq/browserw.htm

次のコードは、ブラウザウィンドウの実際 幅と高さ変数ウェハ内とWINHを設定し、幅及び 高さの値を出力します。ユーザーに非常に古いブラウザがある場合、winWとwinH はそれぞれ630と460に設定されます。

var winW = 630, winH = 460; 
if (document.body && document.body.offsetWidth) { 
winW = document.body.offsetWidth; 
winH = document.body.offsetHeight; 
} 
if (document.compatMode=='CSS1Compat' && 
    document.documentElement && 
    document.documentElement.offsetWidth) { 
winW = document.documentElement.offsetWidth; 
winH = document.documentElement.offsetHeight; 
} 
if (window.innerWidth && window.innerHeight) { 
winW = window.innerWidth; 
winH = window.innerHeight; 
} 
関連する問題