2011-07-07 46 views
1

我正在使用爲整個頁面設置div作爲掩碼。jquery文件寬度

$(document).width(); 

但是,這在IE和Firefox之間的行爲有所不同。在IE中它提供了796,而在Firefox中它提供了789。

在Firefox中,面具適合屏幕。 但在IE中,下面會出現一個額外的滾動條。

我想讓面具適合屏幕。請幫我解決這個問題。

window.width()和100%在調整窗口大小時無濟於事。我不能使用$('body'),因爲我需要以相同的方式計算高度。

在此先感謝。

回答

2

這是試錯和搜索世界上所有literately天

使用pureJS,因爲即使沒有jQuery的正確報告吧!但需要jQuery來識別瀏覽器。我用它來測量iframe中的body,以避免跨域通信的滾動條..你可以調整一下。但核心是有

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

以下代碼設置變量winW和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; 
}