代码改变世界

iframe自适应高度

2011-08-18 15:50  jewelry  阅读(267)  评论(0编辑  收藏  举报

1、自建ifr.js

  function iFrameHeight() {
    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;
    }
  }

2、引用ifr.js;调用如下:

<iframe src="" id="iframepage" name="iframepage" frameBorder=0 scrolling=no width="100%" onLoad="iFrameHeight()" ></iframe>

详细出处参考:http://www.jb51.net/article/15780.htm