2012-02-01 108 views
0

这是非常棘手的情况,我尝试了很多事情,但无法弄清楚。我有以下iframe:与主页侧栏滚动iframe

<div id="content"> <iframe id="iF" name="if" marginwidth="0" marginheight="0" frameborder="0" src=""></iframe> 
</div> 

源是通过jquery输入到此。问题是当源进入时它的高度和宽度都是两个大。所以我看到两个滚动条。无论如何,iframe数据将随主页滚动条一起移动。而不是添加两个不同的滚动条。 这里是我现在看到的图像: double scrollbars

回答

1

您需要在内容填充完成后调整它的大小,这可以通过使用Javascript来完成。

<script type="text/javascript"> 
    function iframeLoaded() 
    { 
     var iFrameID = document.getElementById('idIframe'); 

     if(iFrameID) 
     { 
      // here you can meke the height, I delete it first, then I make it again 
      iFrameID.height = ""; 
      iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px"; 
     } 
    } 
</script> 


<iframe id="idIframe" onload="iframeLoaded()" ... 

其他的解决方案是高度和宽度添加到persent值,如100%,让您的窗口的所有宽度/高度,并隐藏iframe的滚动条。