贴上代码:
$(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"
οnlοad="setIframeHeight(this);"
src=""
style="padding: 0px; margin: 0px; min-height: 750px; width: 100%; border: 0px;">