• IFRAME高度自适应——框架高度等于其页面高度


    <iframe id="mainframe" name="mainframe" src="services/services.asp?owen1=服务理念" onload="this.style.height = parseInt(window.frames['mainframe'].document.body.scrollHeight);" frameborder="0" marginheight="0" marginwidth="0">
    </iframe>

    这段代码是页面加载时自适应,当页面内部发生变化时用以下代码自适应:
    $(window).resize(function(){
    parent.$("#mainframe").height($("body").height());
    });

    以下为非原始JS代码:
    方法一:
    function SetWinHeight(obj)
    {
        var win=obj;
        if (document.getElementById)
        {
            if (win && !window.opera)
            {
                if (win.contentDocument && win.contentDocument.body.offsetHeight) 
                    win.height = win.contentDocument.body.offsetHeight;
                else if(win.Document && win.Document.body.scrollHeight)
                    win.height = win.Document.body.scrollHeight;
            }
        }
    }

    <iframe width="778" align="center" height="200" id="win" name="win" onload="Javascript:SetWinHeight(this)" frameborder="0" scrolling="no"></iframe>

    方法二:
    <script type="text/javascript">
    //** iframe自动适应页面 **//

    //输入你希望根据页面高度自动调整高度的iframe的名称的列表
    //用逗号把每个iframe的ID分隔. 例如: ["myframe1", "myframe2"],可以只有一个窗体,则不用逗号。

    //定义iframe的ID
    var iframeids=["test"]

    //如果用户的浏览器不支持iframe是否将iframe隐藏 yes 表示隐藏,no表示不隐藏
    var iframehide="yes"

    function dyniframesize()
    {
    var dyniframe=new Array()
    for (i=0; i<iframeids.length; i++)
    {
    if (document.getElementById)
    {
    //自动调整iframe高度
    dyniframe[dyniframe.length] = document.getElementById(iframeids);
    if (dyniframe && !window.opera)
    {
    dyniframe.style.display="block"
    if (dyniframe.contentDocument && dyniframe.contentDocument.body.offsetHeight) //如果用户的浏览器是NetScape
    dyniframe.height = dyniframe.contentDocument.body.offsetHeight;
    else if (dyniframe.Document && dyniframe.Document.body.scrollHeight) //如果用户的浏览器是IE
    dyniframe.height = dyniframe.Document.body.scrollHeight;
    }
    }
    //根据设定的参数来处理不支持iframe的浏览器的显示问题
    if ((document.all || document.getElementById) && iframehide=="no")
    {
    var tempobj=document.all? Document.all[iframeids] : document.getElementById(iframeids)
    tempobj.style.display="block"
    }
    }
    }

    if (window.addEventListener)
    window.addEventListener("load", dyniframesize, false)
    else if (window.attachEvent)
    window.attachEvent("onload", dyniframesize)
    else
    window.onload=dyniframesize
    </script>

    方法三:
    function SetCwinHeight(iframeObj) {
                if (document.getElementById) {
                    if (iframeObj) {
                        if (iframeObj.contentDocument && iframeObj.contentDocument.body.offsetHeight) {
                            iframeObj.height = iframeObj.contentDocument.body.offsetHeight + 30;
                        } else if (document.frames[iframeObj.name].document && document.frames[iframeObj.name].document.body.scrollHeight) {
                            iframeObj.height = document.frames[iframeObj.name].document.body.scrollHeight + 30;
                        }
                    }
                }
            }
  • 相关阅读:
    2019年3月6日 980. Unique Paths III
    2019年3月05日 961. N-Repeated Element in Size 2N Array
    2019年3月4日 701. Insert into a Binary Search Tree
    2019年3月1日 804. Unique Morse Code Words
    2019年2月28日 654. Maximum Binary Tree
    2019年2月26日 Unique Email Addresses、To Lower Case、Encode and Decode TinyURL
    Nexus Repository Manager 3 远程命令执行漏洞(CVE-2020-10199)复现
    常见的Web源码泄漏漏洞及其利用
    Nmap-脚本检测CVE漏洞
    Vulnhub-dpwwn-01靶机过关记录
  • 原文地址:https://www.cnblogs.com/cosiray/p/1551272.html
Copyright © 2020-2023  润新知