如何让iframe框架自适应内容高度

来源:互联网 发布:centos 7.4 官方下载 编辑:程序博客网 时间:2024/05/01 20:18

<iframe src="edit-index.html" width="969" id="my_iframe" frameborder="no" marginwidth="0" marginheight="0" scrolling="no"></iframe>

<script language="javascript">

  $(function(){
  var document_height="";

  //iframe自适应高度
  var timeIframe;
  window.onload=function(){
  timeIframe=setTimeout(GetIframeStatus,10);
  }
  function GetIframeStatus()
  {
  var iframe = document.getElementById("my_iframe");
  var iframeWindow=iframe.contentWindow;
  if(iframeWindow.document.readyState=="complete")
  {
  var iframeWidth,iframeHeight;
  iframeWidth=iframeWindow.document.documentElement.scrollWidth;
  iframeHeight=iframeWindow.document.documentElement.scrollHeight;
  iframe.width=iframeWidth;
  iframe.height=iframeHeight;
  }
  else
  {
  timeIframe=setTimeout(GetIframeStatus,10);
  }
  }
  })

</script>

0 0
原创粉丝点击