贴上代码:
$(function() {
//每隔1秒钟调整页面的高度,解决页面中异步请求的数据加载完之后,页面高度随之改变
setInterval(function(){
setIframeHeight(document.getElementById("mainIframe"));
}, 1000);
});//iframe自适应高度
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;
}
}
};<iframe id="mainIframe" name="mainIframe" scrolling="no"
onload="setIframeHeight(this);"
src=""
style="padding: 0px; margin: 0px; min-height: 750px; width: 100%; border: 0px;">
本文介绍了一个使用JavaScript实现的iframe自适应高度的方法。该方法通过定时调整iframe的高度来确保其能够根据内部内容的变化自动扩展,特别适用于那些内容会动态变化的情况。
4880

被折叠的 条评论
为什么被折叠?



