iframe调整自适应高度

<div class="page-content text-center" style="height: calc(100% - 55px);overflow:hidden" >
            <iframe id="iframe" src="/vproject/base/projectview.jsp?id=" th:attrappend="src=${project.id}" onload="changeFrameHeight()" scrolling="no"
                    frameborder="0"
                    name="frame-0"
                    class="page-frame animation-fade"
                    style="width: 100%;height: 100%; "></iframe>

        </div>

js中
function changeFrameHeight() {
var ifm = document.getElementById("iframe");
ifm.height = 0;
// ifm.height = document.documentElement.clientHeight;
//alert(ifm.contentWindow.document.documentElement.scrollHeight);
ifm.height = ifm.contentWindow.document.documentElement.scrollHeight;
/**/
}


window.onresize = function () {
changeFrameHeight();
};
posted @ 2022-08-09 09:29  java璀璨小菜鸟  阅读(200)  评论(0)    收藏  举报