iframe切换内容页仍然能自适应大小代码(含js)

function setIframeHeight(iframe) {
              if (iframe) {
                  var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
                  if (iframeWin.document.body) {
                      iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                  }
              }
            };
            window.onload = function () {
                setIframeHeight(document.getElementById('myiframe'));//iframe的id
}; 


<iframe onload="setIframeHeight(this)" id="myiframe" name="item-ifram" class="ZhaoShangJiaMeng-ifram" src="ZhaoShangJiaMeng-QuanYi.html" frameborder="0" scrolling="no" ></iframe>

 

posted @ 2016-08-02 16:58  怪咖咖  阅读(558)  评论(0编辑  收藏  举报