iframe自适应高度

iframe自适应高度,实现原理是在iframe页面加载完成后将页面的高度赋值到iframe上。

非原创,来自于博客园的留言。

<iframe id="myIframe" src="/src.html" style="width:1220px; border:0px;" scrolling="no" onload="autoHeight()"></iframe>

function autoHeight() {

    var ifr = document.getElementById('myIframe');
    ifr.height = (ifr.contentDocument && ifr.contentDocument.body.offsetHeight)
            || (ifr.contentWindow.document.body.scrollHeight);
}

 

posted @ 2016-09-01 14:08  京沙  阅读(139)  评论(0编辑  收藏  举报