[英]To dynamically increase the height of the iframe
I have a page where I have inserted an iframe. 我在一个页面中插入了iframe。 When the child page is loaded, I dynamically set the value of the iframe using the below code:
加载子页面时,我使用以下代码动态设置iframe的值:
Parent Page: 父页面:
`<iframe src="/test.do" id="iframeTest">`
function setIframeHeight(height) {
$("#iframeTest").height(height);
}
Child page: test.jsp: 子页面: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);
}
Now, whenever the child page's height increase (ie whenever a new <tr>
is included), I will call the parent.setIframeHeight()
so that the iframe height is increased. 现在,每当子页面的高度增加时(即,每当包含新的
<tr>
),我都将调用parent.setIframeHeight()
,以使iframe的高度增加。 I tested this and works fine for me. 我对此进行了测试,对我来说效果很好。 I wanted to know whether is it the right way to increase the iframe height?
我想知道是否是增加iframe高度的正确方法? Or is there any other alternative.
还是有其他选择。
try this: If your Child page Content Changes Continuously or after some Intervals: 请尝试以下操作:如果您的子页面内容连续更改或在某些时间间隔后更改:
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";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.