iframe自适应内容高度(亲测靠谱)
废话不多说,上代码:html之iframe:
<iframe name="menuFrame" id="menuFrame" onload="reinitIframe()" style="overflow:visible;"
scrolling="no" height="100%" width="100%">
</iframe>
javascript:
window.onresize = function () {
reinitIframe();
}
function reinitIframe(){
var iframe = document.getElementById("menuFrame");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.min(bHeight, dHeight);
iframe.height = height+50;
// console.log(iframe.height);
}catch (ex){}
}
// 定时触发
window.setInterval("reinitIframe()", 200);
关键在这里window.setInterval("reinitIframe()", 200);
本文转自:https://blog.csdn.net/qq_28333105/article/details/91449921