iframe高度自适应

function reinitIframe() {

            var iframe = document.getElementById("infoIframe");

            try {

                var bHeight = iframe.contentWindow.document.body.scrollHeight;

                var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;

                var height = Math.max(bHeight, dHeight);

                iframe.height = height;

                //changeFileNum();

            } catch (ex) { }
            
        }
        window.setInterval("reinitIframe()", 200);

  此方法是按照指定德时间间隔来修改iframe的高度的,所以时间间隔最好不要太短。

原文地址:https://www.cnblogs.com/stevenjson/p/3379527.html