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>
    

      

  • 相关阅读:
    51nod 1380 夹克老爷的逢三抽一 堆 脑洞题
    洛谷P2168 荷马史诗 堆 哈夫曼树
    HDU 4343 Interval query 倍增思想, DP
    洛谷P1969 积木大赛 贪心 差分
    codves1052 地鼠游戏 贪心
    hdu6031 Innumerable Ancestors
    Codeforces 278C Learning Languages(并查集) 求连通块
    [LeetCode]80. Remove Duplicates from Sorted Array II删除数组中的重复值
    [LeetCode]86. Partition List分离链表
    [LeetCode]42. Trapping Rain Water雨水填坑
  • 原文地址:https://www.cnblogs.com/zhoushiya/p/12107298.html
Copyright © 2011-2022 走看看