2017-03-09 86 views
0

我需要根據內容設置iframe的高度。如何根據內容設置iframe高度?

<iframe src="../graphs/Average.html" alt="##graphname" width=100% height=680px overflow:visible frameborder=0 class="general" style="border-collapse: collapse;" noresize onload="document.getElementById('p').style.display='none';"></iframe> 

我也曾嘗試:<style> div{overflow:visible} </style> 但它也不能正常工作。

+0

這裏已經回答:HTTP://計算器。 COM /問題/ 819416 /調節寬度-height-of-iframe-to-fit-with-content-in-it –

+3

[調整iframe的寬度以適合其中的內容]可能的副本(http://stackoverflow.com/questions/819416/adjust- width-height-of-iframe-to-fit-with-content-in-it) –

+1

[根據內部的內容製作iframe高度動態的可能的重複 - JQUERY/Javascript](http://stackoverflow.com/questions/9162933/make-iframe-height-dynamic-based-content-inside-jquery-javascript) –

回答

0

爲此,您可以使用以下JScode:

<iframe id="iframe" src="../graphs/Average.html" alt="#graphname" width="100%" height="680" frameborder=0 class="general" style="border-collapse: collapse;" noresize onload="document.getElementById('p').style.display='none';"></iframe>  

使用JavaScript

document.getElementById("iframe").style.height = $('#iframe').get(0).contentWindow.document.body.offsetHeight + 'px' 

使用jQuery

$('#iframe').height($('#iframe').get(0).contentWindow.document.body.offsetHeight + 'px'); 
+0

這也溢出:可見不工作。滾動條即將到來,我需要頁面全長的數據不在滾動中。 –

相關問題