zoukankan      html  css  js  c++  java
  • Iframe自适应其加载的内容高度

    <SCRIPT type="text/javascript" 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 h1=0, h2=0;
                            a[i].parentNode.style.height = a[i].offsetHeight +"px";
                            a[i].style.height = "10px";
                            if(document.documentElement&&document.documentElement.scrollHeight)
                            {
                                h1=document.documentElement.scrollHeight;
                            }
                            if(document.body) h2=document.body.scrollHeight;

                            var h=Math.max(h1, h2);
                            if(document.all) {h += 4;}
                            if(window.opera) {h += 1;}
                            a[i].style.height = a[i].parentNode.style.height = h +"px";
                        }
                    }
                }
            }
            catch (ex){}
        }
        if(window.attachEvent)
        {
            window.attachEvent("onload",  iframeAutoFit);
            //window.attachEvent("onresize",  iframeAutoFit);
        }
        else if(window.addEventListener)
        {
            window.addEventListener('load',  iframeAutoFit,  false);
            //window.addEventListener('resize',  iframeAutoFit,  false);
        }
    </script>

  • 相关阅读:
    Redis系列二 Redis数据库介绍
    Redis系列一 Redis安装
    SpringData系列四 @Query注解及@Modifying注解
    SpringData系列三 Repository Bean 方法定义规范
    SpringData系列二 Repository接口
    SpringData系列一 Spring Data的环境搭建
    ThinkPHP3.1.3 Fast & Simple OOP PHP Framework 显示错误
    STL学习系列之一——标准模板库STL介绍
    STL之二:vector容器用法详解
    STL使用总结
  • 原文地址:https://www.cnblogs.com/limshirley/p/1508809.html
Copyright © 2011-2022 走看看