2011-10-19 72 views
3

iframe的內容是否爲具有母版頁的asp.net網站時,如何設置iFrame內容的高度?如何爲所有瀏覽器設置iFrame內容的高度?

有誰知道任何jQuery插件?

更新 能正常工作,在IE瀏覽器,但在Chrome失敗和firefox

function resizeFrame(f) { 
     f.style.height = f.contentWindow.document.body.scrollHeight + "px"; 
    } 

調用它身體的onload()

身體的onload =「resizeFrame (document.getElementById('MainIFrame'))「

的iframe代碼

 <iframe id="MainIFrame" class="autoHeight" runat="server" marginwidth="0" style="margin: auto; " 
       frameborder="0" width="100%" scrolling="no" > 
       </iframe> 
+0

更多信息將是很好':)' –

+0

一些代碼更新中...我喜歡我的iframe有相同的高度頁面 – Zeus

+0

見:http://stackoverflow.com/questions/247128/how-to-auto-size-an-iframe加上關於這個問題的其他答案。 –

回答

2

腳本適用於所有瀏覽器

<script type="text/javascript" language="javascript"> 
     function resizeIframe(dynheight) { 
      try { 
       var f = document.getElementById("autosizeframe"); 
       document.getElementById("autosizeframe").height = parseInt(dynheight) + 10; 
       if (f.contentDocument) { 
        f.height = f.contentDocument.documentElement.scrollHeight + 30; //FF 3.0.11, Opera 9.63, and Chrome 
       } else { 
        f.height = f.contentWindow.document.body.scrollHeight + 30; //IE6, IE7 and Chrome 

       } 
      } 

      catch (err) { 
       alert('Err: ' + err.message); 
       window.status = err.message; 
      } 
     } 

     window.onload = function() { 
      var height = document.body.scrollHeight; 
      resizeIframe(height); 

     };         

    </script> 
相關問題