zoukankan      html  css  js  c++  java
  • 用javascript动态调整iframe高度兼容多种浏览器

    首先,在你的主页面上必须包含以下这段javascript代码:

    <script language="Javascript">
    var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
    //extra height in px to add to iframe in FireFox 1.0+ browsers
    var FFextraHeight=getFFVersion>=0.1? 16 : 0

    function dyniframesize(iframename) {
       var pTar = null;
       if (document.getElementById){
         pTar = document.getElementById(iframename);
       }
       else{
         eval('pTar = ' + iframename + ';');
       }
       if (pTar && !window.opera){
         //begin resizing iframe
         pTar.style.display="block"
        
         if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
           //ns6 syntax
           pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight;
         }
         else if (pTar.Document && pTar.Document.body.scrollHeight){
           //ie5+ syntax
           pTar.height = pTar.Document.body.scrollHeight;
         }
       }
    }
    </script>

    然后对于主页面用到iframe的地方添加代码:

    <iframe id="myTestFrameID"
    onload="javascript:{dyniframesize('myTestFrameID');}"
    marginwidth=0 marginheight=0 frameborder=0
    scrolling=no src="/myiframesrc.php"
    width=200 height=100></iframe>

  • 相关阅读:
    android一个纠结的VFY错误
    icon在线编辑和查找工具
    增加Android可用内存
    android对大图片的缓存处理
    MySQL sql语句大全
    Canvas
    Docker 微服务教程
    Docker 入门教程
    项目管理
    JavaScript standard 代码规范的全文
  • 原文地址:https://www.cnblogs.com/88223100/p/1238250.html
Copyright © 2011-2022 走看看