2011-05-05 74 views
1

我使用此代碼依賴於遠程站點的內容動態調整大小的iFrame:如何動態調整頁面高度不同的iFrame?

http://solidgone.org/Set-IFRAME-height-based-on-size-of-remotely-loaded-content

不過,在遠程站點,還有其他網頁也是如此。發生什麼事是,當我點擊遠程站點上的鏈接(在iFrame內部)時,高度不會相應改變。相反,它使用我們最初在iFrame上設置的頁面高度。在這種情況下,它使用remote.php的高度(這是相當高的):

<iframe id='local-iframe' width='1' height='1' frameborder='0' scrolling='no' src ='http://remotesite.com/remote.php'></iframe> 
</iframe> 

的另一件事是,即使我表示SCROLLING =「不」上的iFrame,一旦我點擊了一個鏈接內iFrame,滾動條重新出現。

有沒有解決這個問題的方法?我們做錯了什麼?

回答

2

在這個網站(下圖)的代碼工作對我來說,雖然我努力讓邊界消失......

http://ramanisandeep.wordpress.com/2009/12/16/how-to-dynamically-adjust-an-iframe’s-height/


頁面上

插入iframe的

<iframe scrolling='no' frameborder='0' id='frmid' src=’getad.aspx' 
     onload='javascript:resizeIframe(this);'> 
</iframe> 

使用此JavaScript來調整基於高度的iframe的大小&寬度的子頁面

<script language="javascript" type="text/javascript"> 
function resizeIframe(obj) 
{ 
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; 
    obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px'; 
} 
</script>