当其中包含的 iFrame 改变高度时,我正在尝试找到一种调整嵌入 div 大小的方法。
这基本上就是我所拥有的:
<div>
<iframe src="www.somesite.com"></iframe>
</div>
所以 iFrame 内容会改变高度,我希望包含它的 div 相应地调整大小。
我可以使用任何神奇的 jQuery 或 Bootstrap(页面同时使用)?
最佳答案
试试这个,
<div id="iframeContainer">
<iframe src="www.somesite.com" id="contentIframe" onload="setContentHeight()"></iframe>
</div>
<script type="text/javascript">
function setContentHeight() {
var iframe = $('#contentIframe').contents();
if(iframe) {
var height = iframe.height();
$("#iframeContainer").height(height);
}
}
</script>
关于javascript - 当 iframe 改变高度时调整容器大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48518263/