根据iframe中内容设置iframe显示的高度

来源:互联网 发布:网络维护是做什么的 编辑:程序博客网 时间:2024/05/17 09:29


<div class="content-body">          <iframe class="frame" src="<?php echo base_url()?>assets/file/help/install_php.html" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>      </div>

根据iframe中内容设置iframe显示的高度

//设置iframe的高度     autoResize();     function autoResize() {        var iframeHeight = $(".frame").contents().find("body").height();        $(".frame").css("height",iframeHeight+20);     }

或者

function autoResize() {          var iFrames = $('.frame');          function iResize() {              for (var i = 0, j = iFrames.length; i < j; i++) {                iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';              }          }                     if ($.browser.safari || $.browser.opera) {             iFrames.load(function(){                 setTimeout(iResize, 0);             });             for (var i = 0, j = iFrames.length; i < j; i++) {                  var iSource = iFrames[i].src;                  iFrames[i].src = '';                  iFrames[i].src = iSource;             }          } else {             iFrames.load(function() {                 this.style.height = this.contentWindow.document.body.offsetHeight + 'px';             });          }     }