zoukankan      html  css  js  c++  java
  • iframe宽高自适应

    iframe子页面结尾添加本script

    iframe子页面结尾添加本script
    
    <script type="text/javascript">
            function iframeAuto() {
                try {
                    if (window != parent) {
                        //定位需要调整的frame框架(在父级窗口中查找)
                        var a = parent.document.getElementsByTagName("iframe");
                        for (var i = 0; i < a.length; i++) {
                            if (a[i].contentWindow == window) {
                                var h1 = 0, h2 = 0;
                                a[i].parentNode.style.height = a[i].offsetHeight + "px";
                                a[i].style.height = "10px"; //首先设置高度为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) { }
            }
            //事件绑定的方法,支持IE5以上版本
            if (window.attachEvent) {
                window.attachEvent("onload", iframeAuto);
            }
            else if (window.addEventListener) {
                window.addEventListener('load', iframeAuto, false);
            }
       
        </script>
    

      

  • 相关阅读:
    python学习笔记 async and await
    python学习笔记 异步asyncio
    python学习笔记 协程
    python学记笔记 2 异步IO
    python学习笔记 可变参数关键字参数**kw相关学习
    逆波兰表达式 栈表达式计算
    Codeforces 270E Flawed Flow 网络流问题
    Codeforces 219D Choosing Capital for Treeland 2次DP
    kuangbin 带你飞 概率期望
    函数式编程思想:以函数的方式思考,第3部分
  • 原文地址:https://www.cnblogs.com/zhoushiya/p/12107298.html
Copyright © 2011-2022 走看看