zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    leetcode 78 子集
    leetcode 404 左叶子之和
    《数学有意思》28杠杆原理 29信息革命 30可信的数学
    《数学有意思》25中心极限定理 26混沌现象 27焦虑
    《数学有意思》22算术和几何 23统计学 24概率
    《数学有意思》19数学语言 20函数 21无理数
    《数学有意思》16归纳法 17因果关系 18物理学
    《数学有意思》13度量的本质 14度量单位 15科学也是一种模型
    《数学有意思》10思维工具 11选择合适的数学模型 12几何学
    《数学有意思》07公理是“公认的道理”吗 08什么是好的公里系统 09数学模型
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/2690550.html
Copyright © 2011-2022 走看看