iframe自适应高度,根据src中页面来得到。

  在页面布局时,div+iframe能根据具体的大小进行布局。但,对于iframe的适应大小,仍需js获取内部html文件来改变。

  function reinitIframe(){
  var iframe = document.getElementsByName("H_viewFrame")[0];//获得name为H_viewFrame的iframe
  try{  
  iframe.height =  iframe.contentWindow.document.body.scrollHeight;

     // iframe.height =  iframe.contentWindow.document.documentElement.scrollHeight;  //获得的高度根据头部文件的不同而有所差异
  }catch (ex){}
  }
  window.setInterval("reinitIframe()", 200);

原文地址:https://www.cnblogs.com/lamiyiyi/p/3419620.html