我有一個iframe,當內容自動刷新(每隔幾分鐘)或用戶與它交互時,我想調整其大小以匹配其內容。雖然內容在同一個域中,但我很難修改內容。理想情況下,iframe會自動調整其內容的大小。在內容刷新或更新時調整iframe的大小
可調整大小隻有一次電流代碼:
<iframe id="ganglia-frame" src="ganglia.url" width="100%" height="500%">
blah not supported blah
</iframe>
<script language="Javascript">
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow ||
iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height =
iframeWin.document.documentElement.scrollHeight ||
iframeWin.document.body.scrollHeight;
}
}
}
$(window).load(function() {
setIframeHeight(document.getElementById('ganglia-frame'));
});
</script>
相關問題:Adjust width height of iframe to fit with content in it
你看看http://stackoverflow.com/questions/153152/resizing-an-iframe-based-on-content,非常全面! –
@DaneBalia如果您指的是接受的答案,它需要修改iframe內容代碼(請參閱第2段),我不能這樣做。 – walrii