2014-04-17 19 views
0

工作我使用這個腳本來調整iframe的高度,並根據內容自動寬度..的iFrame自動調整不會在Firefox中使用JavaScript

<script language="JavaScript"> 


function autoResize(id){ 
    var newheight; 
    var newwidth; 

    if(document.getElementById){ 
     newheight=document.getElementById(id).contentWindow.document .body.scrollHeight; 
     newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth; 
    } 

    document.getElementById(id).height= (newheight) + "px"; 
    document.getElementById(id).width= (newwidth) + "px"; 
} 
</script> 

在調用的iFrame的onload這個功能..

<iframe src="index.htm" scrolling='no' width="100%" height="100%" name="CHANGETHIS" id="CHANGETHIS" marginheight="0" frameborder="0" onLoad="autoResize('CHANGETHIS');"></iframe> 

考慮我使用超級鏈接<a href="index2.htm">Redirect</a>

如果我點擊超鏈接Redirect,它被重定向到index2.htm FIL e與iframe根據內容自動調整大小。如果我回去(瀏覽器後退或後退按鈕)到上一頁(index.htm),iframe自動調整大小不工作只在Firefox中..它在IE中工作正常..

是否有任何解決方案也使用javascript或jquery在Firefox中工作?

+0

$(窗口)。在( '調整',函數(){...}); ! –

+0

歡迎C - 鏈接..你已經回答了我的許多問題..你可以解釋這個jQuery嗎?如何使用它? –

回答

1

使用此:onresize="autoResize('CHANGETHIS');"

<iframe src="index.htm" scrolling='no' width="100%" height="100%" name="CHANGETHIS" id="CHANGETHIS" marginheight="0" frameborder="0" onload="autoResize('CHANGETHIS');" onresize="autoResize('CHANGETHIS');"></iframe> 
+0

我在javascript中提到的autoresize函數呢?我可以刪除嗎? –

+0

nope,這是你的功能,如果你使用onresize內聯js然後複製我的答案是,如果你想在js文件中使用,然後在調整大小函數內放置你的代碼。 –

+0

不能讓你兄弟:( –