zoukankan      html  css  js  c++  java
  • 【经验分享】Iframe自适应其加载的内容高度

    main.htm:

    <html> 
        <head> 
          <meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312'> 
          <meta  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com'> 
          <title>iframe自适应加载的页面高度</title> 
        </head> 
       
        <body>
            <iframe src="child.htm"></iframe>
        </body>
    </html>

    child.htm:

    <html> 
    <head> 
      <meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312'> 
      <meta  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com'> 
      <title>iframe  自适应其加载的网页(多浏览器兼容)</title> 
      <script  language=javascript>
      function iframeAutoFit()
      {
          try
          {
            if(window!=parent)
            {
              var a = parent.document.getElementsByTagName("IFRAME");
                for(var i=0; i<a.length; i++) //author:meizz
                {
                  if(a[i].contentWindow==window)
                  {
                      var h = document.body.scrollHeight;
                      if(document.all) {h += 4;}
                      if(window.opera) {h += 1;}
                      a[i].style.height = h;
                  }
                }
            }
          }
          catch (ex)
          {
            alert("脚本无法跨域操作!");
          }
      }
      if(document.attachEvent)  window.attachEvent("onload",  iframeAutoFit); 
      else  window.addEventListener('load',  iframeAutoFit,  false); 
      </script> 
    </head> 
    <body> 
      <div  style="  200;  height:  400;  background-color:  yellow"> 
          iframe  自适应其加载的网页(多浏览器兼容) 
      </div> 
    </body> 
    </html>
  • 相关阅读:
    ARC108解题报告
    整体dp小结
    SAM学习笔记&AC自动机复习
    Error creating bean with name 'bootstrapImportSelectorConfiguration':
    responseBody
    无力回天的CSP2020
    NOIP2020游记
    2020国家集训队作业选做
    flutter开发使用AnnotatedRegion修改状态栏字体颜色,导致导航栏也变黑了的解决方法
    flutter使用InkWell点击没有水波纹效果的解决方法
  • 原文地址:https://www.cnblogs.com/a311300/p/1300967.html
Copyright © 2011-2022 走看看