动态增加iframe的高度
To dynamically increase the height of the iframe
我有一个页面,我插入了一个iframe。当加载子页面时,我使用下面的代码动态设置iframe的值:
父页面:
`<iframe src="/test.do" id="iframeTest">`
function setIframeHeight(height) {
$("#iframeTest").height(height);
}
子页面:test.jsp:
<div id="test">
<table>The whole content will be inside this div</table>
</div>
$(document).ready(function() {
var height = $("#test").outerHeight();
parent.setIframeHeight(height);
}
现在,每当子页面的高度增加时(即每当包含新的<tr>
时),我将调用parent.setIframeHeight()
以增加iframe的高度。我测试了这个,对我来说很好。我想知道这是增加框架高度的正确方法吗?或者还有其他选择吗?
试试这个:如果您的子页面内容连续更改或间隔一段时间后更改:
setInterval(function(){iframeLoaded}, 2000);
function iframeLoaded() {
var iFrameID = document.getElementById('iframeTest');
if(iFrameID) {
// here you can make the height, I delete it first, then I make it again
iFrameID.height = "";
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
相关文章:
- 获取iframe内容的宽度-高度
- 使用javascript设置iframe的高度
- iframe上的100%自动高度
- 设置iFrame的高度
- 调整追加的 iframe 的高度
- 动态增加 iframe 高度
- 调整不同域上iframe的高度
- iframe高度100%不起作用
- 多个页面 iframe,高度加载
- 当内容显示在FireFox的iFrame中时,jQuery高度问题
- 加载新内容时调整iframe的高度
- 动态iframe高度-似乎需要重新加载页面
- 如何告诉 iframe 将图像链接调整为给定的宽度和高度
- 根据提交单击动态调整 iFrame 的高度
- 根据内容设置 iFrame 宽度和高度
- 如何更改其内容的 Iframe 高度(两者都来自同一域)
- 更改花式框iframe的大小-我可以更改宽度,但不能更改高度
- iFrame 不会扩展到完整的内容高度,即使有 jQuery 脚本以它为目标
- 同位素布局中的动态iframe高度
- iFrame - 在 iFrame 中更改内容时自动设置高度