让外层iframe的高度自适应加载页面高度

来源:互联网 发布:mac中截屏键 编辑:程序博客网 时间:2024/05/01 08:32

1.js代码设置

function setiframe(id) {

    var Iframe = document.getElementById(id);
    try {
        // 声明变量取值
        var bHeight = Iframe.contentWindow.document.body.scrollHeight;
        var dHeight = Iframe.contentWindow.document.documentElement.scrollHeight;
        var height = Math.max(bHeight, dHeight); // 取最大值
        Iframe.height = height;
    } catch (ex) { }
}


window.setInterval("setiframe('right_iframe')", 10);   //0.01秒周期调用函数

2.对iframe进行设置:
<iframe name="right" id="right_iframe" src="right.html" frameborder="false" scrolling="no" width="100%"                  height="100%" allowtransparency="true" onload="this.height=160" >
</iframe> 
0 0
原创粉丝点击