• iframe 自适应高度


    /**
             * 页面撑开
             */
            function iframeAutoFit()
            {
                try
                {
                    if (window != parent)
                    {
                        var a = parent.document.getElementById("myiframe");
                        if (a.contentWindow == window)
                        {
                            var h1 = 0, h2 = 0;
                            a.parentNode.style.height = a.offsetHeight + "px";
                            a.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 += 0;
                            }
                            if (window.opera) {
                                h += 1;
                            }
                            a.style.height = a.parentNode.style.height = h + "px";
                        }
                    }
                }
                catch (ex) {
                }
            }
            if (window.attachEvent)
            {
                window.attachEvent("onload", iframeAutoFit);
            }
            else if (window.addEventListener)
            {
                window.addEventListener('load', iframeAutoFit, false);
            }
        </script>

    <iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>
    看到了吧,关键就在于onload="this.height=iFrame1.document.body.scrollHeight"!

    <script type="text/javascript" language="javascript">  
    function iFrameHeight() {  
    var ifm= document.getElementById("iframepage");  
    var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;  
    if(ifm != null && subWeb != null) {
       ifm.height = subWeb.body.scrollHeight;
    }  
    }  
    </script>

    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;
    }
    }
    }


     


    <script language="javascript" type="text/javascript">
    function dyniframesize(down) {
    var pTar = null;
    if (document.getElementById){
    pTar = document.getElementById(down);
    }
    else{
    eval('pTar = ' + down + ';');
    }
    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 +20;
    pTar.width = pTar.contentDocument.body.scrollWidth+20;
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight){
    //ie5+ syntax
    pTar.height = pTar.Document.body.scrollHeight;
    pTar.width = pTar.Document.body.scrollWidth;
    }
    }
    }
    </script>
    <iframe src ="/default2.aspx" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');" width="100%">
    </iframe>


    <html>
    <head>
    <script>
    function SetCwinHeight(obj)
    {
    var cwin=obj;
    if (document.getElementById)
    {
    if (cwin && !window.opera)
    {
    if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
    cwin.height = cwin.contentDocument.body.offsetHeight + 20; //FF NS
    else if(cwin.Document && cwin.Document.body.scrollHeight)
    cwin.height = cwin.Document.body.scrollHeight + 10;//IE
    }
    else
    {
    if(cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
    cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera
    }
    }
    }
    </script>
    </head>
    <body>
    <iframe src="20103622440.html" onload="SetCwinHeight(this);" width="600px">
    </body>
    </html>

  • 相关阅读:
    对post提交数据Content-Type的理解
    预加载的实现方式
    ajax跨域简单请求与复杂请求
    web前端图片模糊到清晰的实现过程
    vue子组件调用父组件的方法
    vue子组件如何向父组件传值
    如何实现下拉弹出框渐渐弹出
    DynamicObject扩展--实现JSON和DynamicObject的序列化与反序列化
    解决 Bash On Windows 下载慢或无法下载的问题
    NPOI扩展--判断指定单元格是否为合并单元格和输出该单元格的行列跨度(维度)
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/2690550.html
Copyright © 2020-2023  润新知