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

iframe 自适应高度

时间:2015-05-25 14:28:14      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

<iframe id="iframePage" name="iframePage" src="http:www.xxx.com" scrolling="no" height="100%" width="1300" onload="Javascript:setWinHeight()" ></iframe>
<iframe id="iframePage" name="iframePage" src="http:www.xxx.com" scrolling="no" height="100%" width="1300" onload="Javascript:setWinHeight()" ></iframe>
function setWinHeight() {
    setInterval(setIframeHeight, 2000);
}

function setIframeHeight(){
    var ifm= document.getElementById("iframePage");
    var subWeb = document.frames ? document.frames["iframePage"].document : ifm.contentDocument;
    if(ifm != null && subWeb != null) {
        ifm.height = subWeb.body.scrollHeight;
    }
}

 

如果iframe 的页面是通过ajax动态加载的,那么需要通过 setInterval来修改iframe的高度,

如果iframe的页面是静态的页面, 则onload方法直接调用setIframeHeight方法就OK了。

 

iframe 自适应高度

标签:

原文地址:http://www.cnblogs.com/zhonghan/p/4527623.html

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