码迷,mamicode.com
首页 > 其他好文 > 详细

iframe自适应高度

时间:2016-09-01 14:46:40      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

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);
}

 

iframe自适应高度

标签:

原文地址:http://www.cnblogs.com/jingsha/p/5829607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!