现页面上有三个iframe ,一个控制顶部,一个控制左边,一个控制右边。
如下:
<table  cellSpacing="0" cellPadding="0" width="920" align="center" border="0"
 style="border-right: #cccccc 1px solid; border-top: #cccccc 1px solid; border-left: #cccccc 1px solid; border-bottom: #cccccc 1px solid;">
<tr>
<td height="190" style=" BORDER-BOTTOM: #009900 1px solid"><iframe src="top.aspx" frameBorder="0" width="100%" scrolling="no"  height="190"></iframe>
</td>
</tr>
<tr >
<td  >
<TABLE id="Table1"  cellSpacing="0" cellPadding="0" width="100%" align="center" border="0" height="100%" >
<TR>
<td width="20%"  ><iframe   id="left" src="admin_left.aspx"  frameBorder="0" width="100%"  height="980" scrolling="no"  > </iframe>
</td>
<TD width="80%" ><iframe id="main" name="main"   src="admin_main.aspx"   frameBorder="0" width="100%"  height="980" scrolling="no"  > </iframe>
</TD>
</TR>
</TABLE>
</td>
</tr>
<tr>
<td height="100" style=" BORDER-top: #009900 1px solid">
<iframe src="../foot.aspx" frameBorder="0" width="100%"  scrolling="no" height="100"></iframe>
</td>
</tr>
</table>
问题是:当点击左边的菜单时,如何让左边的iframe和右边的iframe的高度随新打开的页面的高度变化面变化。 我用梅花雪的方法能实现右边iframe的高度随之变化,但左边iframe菜单确自动下移,多出来很多空白。

解决方案 »

  1.   

    这种方法也不行
    <script language="JavaScript"> 
    //** iframe自动适应页面 **////输入你希望根据页面高度自动调整高度的iframe的名称的列表
    //用逗号把每个iframe的ID分隔. 例如: ["myframe1", "myframe2"],可以只有一个窗体,则不用逗号。//定义iframe的ID
    var iframeids=["content"]//如果用户的浏览器不支持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[i]);
    if (dyniframe[i] && !window.opera)
    {
    dyniframe[i].style.display="block"
    if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //如果用户的浏览器是NetScape
    dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight; 
    else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //如果用户的浏览器是IE
    dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
    }
    }
    //根据设定的参数来处理不支持iframe的浏览器的显示问题
    if ((document.all || document.getElementById) && iframehide=="no")
    {
    var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
    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>
      

  2.   

    这是梅花雪的方法,请大虾门看看有什么解决方法
    <script type="text/javascript">
        <!--
        function iframeAutoFit()
        {
            try
            {
                if(window!=parent)
                {
                    var a = parent.document.getElementsByTagName("IFRAME");
                    for(var i=0; i<a.length; i++) //author:meizz
                    {
                        if(a[i].contentWindow==window)
                        {
                            var h1=0, h2=0;
                            a[i].parentNode.style.height = a[i].offsetHeight +"px";
                            a[i].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 += 4;}
                            if(window.opera) {h += 1;}
                            a[i].style.height = a[i].parentNode.style.height = h +"px";
                        }
                    }
                }
            }
            catch (ex){}
        }
        if(window.attachEvent)
        {
            window.attachEvent("onload",  iframeAutoFit);
            //window.attachEvent("onresize",  iframeAutoFit);
        }
        else if(window.addEventListener)
        {
            window.addEventListener('load',  iframeAutoFit,  false);
            //window.addEventListener('resize',  iframeAutoFit,  false);
        }
        //-->
        </script>  
      

  3.   

    网上搜得:
    <script>
    function dyniframesize(iframename)
    {
    var pTar = null;
    if (document.getElementById)
    {
    pTar = document.getElementById(iframename);
    }
    else
    {
    eval('pTar = ' + iframename + ';');
    }
    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 + FFextraHeight;
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight)
    { //ie5+ syntax
    pTar.height = pTar.Document.body.scrollHeight;
    }
    }
    }
    </script>
      

  4.   

    原来是要联动啊我直接给你看我针对类似问题的脚本源码吧// frameId是自己,frameOtherId是边上那个,frameTopId是顶层的frame(如果存在这个嵌套的话)
    function SetFrameHeight(height, frameId, frameOtherId, frameTopId)
    {
    if (top == parent) return; var frame = parent.document.getElementById(frameId);
    if (frame == null) return; var frameTop = top.document.getElementById(frameTopId);
    var frameOther = parent.document.getElementById(frameOtherId);
    if (frameTop != null && frameOther != null)
    {
    var windowContent = frameOther.contentWindow;
    var bodyHeight = 0; if (windowContent != null && windowContent.document.body.scrollHeight)
    { //ie5+ syntax
    bodyHeight = windowContent.document.body.scrollHeight;
    }
    else if (frameOther.contentDocument && frameOther.contentDocument.body.offsetHeight)
    { //ns6 syntax
    frameTop.style.display = "block";
    bodyHeight = frameOther.contentDocument.body.offsetHeight + FFextraHeight;
    } if (height <= bodyHeight) height = bodyHeight;
    //height += 20;
    frameTop.height = height;
    } frame.style.height = height + "px";}
      

  5.   

    在右边的iframe包含的页面里加上
    body onload="SetFrameHeight(document.body.scrollHeight, 右边的iframe id, 左边的iframe id);"即可
      

  6.   

    还是不行,没有起作用。是这样调用吗
    <body topmargin="0" onload="SetFrameHeight(document.body.scrollHeight,'main','left');" >
      

  7.   

    main是右边的ifrmae id 
    left是左边的ifrmae id 
      

  8.   

    以上修改要在admin_main.aspx中进行我的实现是用frameset的没有测试过iframe的情况
      

  9.   

    <body topmargin="0" onload="SetFrameHeight(document.body.scrollHeight,main,left);" >
    <body topmargin="0" onload="SetFrameHeight(document.body.scrollHeight,"main","left");" >
    上面调用也不行。
      

  10.   

    那看来在iframe中此方法不行了,不过还是谢谢你。
      

  11.   

    http://blog.csdn.net/jxufewbt/archive/2006/05/24/752458.aspx
      

  12.   

    这是我用过的
    <script type="text/javascript">   
        var   iframeids=["message"]   
        var   iframehide="yes"   
        function   dyniframesize()     
        {   
          var   dyniframe=new   Array()   
          for   (i=0;   i<iframeids.length;   i++)   
          {   
            if   (document.getElementById)   
            {   
              dyniframe[dyniframe.length]   =   document.getElementById(iframeids[i]);   
              if   (dyniframe[i]   &&   !window.opera)   
              {   
                dyniframe[i].style.display="block"   
                if   (dyniframe[i].contentDocument   &&   dyniframe[i].contentDocument.body.offsetHeight)   
                  dyniframe[i].height   =   dyniframe[i].contentDocument.body.offsetHeight + 50;     
                else   if   (dyniframe[i].Document   &&   dyniframe[i].Document.body.scrollHeight)   
                  dyniframe[i].height   =   dyniframe[i].Document.body.scrollHeight + 50;   
              }   
            }   
            if   ((document.all   ||   document.getElementById)   &&   iframehide=="no")   
            {   
              var   tempobj=document.all?   document.all[iframeids[i]]   :   document.getElementById(iframeids[i])   
              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><iframe src="message.aspx" id="message" runat="server" frameborder="0" width="100%">
    </iframe>
      

  13.   

    to jxufewbt(我的目标是5星) 我试了,也不起作用
    to lxs5i5j() 我也用过这种方法,但不起作用,是把它放到iframe页面吗?
      

  14.   

    main.htm:<html> 
        <head> 
           <meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312' /> 
           <meta  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com' /> 
           <title>iframe自适应加载的页面高度</title> 
        </head> 
        
        <body>
            <div><iframe src="child.htm"></iframe></div>
        </body>
    </html>child.htm:<html> 
    <head> 
        <meta  http-equiv='Content-Type'  content='text/html;  charset=gb2312' /> 
        <meta  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com' /> 
        <title>iframe  自适应其加载的网页(多浏览器兼容)</title> 
        <script type="text/javascript">
        <!--
        function iframeAutoFit()
        {
            try
            {
                if(window!=parent)
                {
                    var a = parent.document.getElementsByTagName("IFRAME");
                    for(var i=0; i<a.length; i++) //author:meizz
                    {
                        if(a[i].contentWindow==window)
                        {
                            var h1=0, h2=0;
                            a[i].parentNode.style.height = a[i].offsetHeight +"px";
                            a[i].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 += 4;}
                            if(window.opera) {h += 1;}
                            a[i].style.height = a[i].parentNode.style.height = h +"px";
                        }
                    }
                }
            }
            catch (ex){}
        }
        if(window.attachEvent)
        {
            window.attachEvent("onload",  iframeAutoFit);
            //window.attachEvent("onresize",  iframeAutoFit);
        }
        else if(window.addEventListener)
        {
            window.addEventListener('load',  iframeAutoFit,  false);
            //window.addEventListener('resize',  iframeAutoFit,  false);
        }
        //-->
        </script> 
    </head> 
    <body>
        <table border="1" width="200" style="height: 400px; background-color: yellow">
            <tr>
                <td>iframe  自适应其加载的网页(多浏览器兼容,支持XHTML)</td>
            </tr>
        </table>
    </body> 
    </html> 很多人反应在IE7里使用它会死机,那是因为在自适应高度时触发了 window.onresize 事件,而这个事件又去调用这个调整 <iframe> 高度的函数,产生了死循环调用。//给你一段代码!你看看!费那事干吗!
      

  15.   

    Click the link to solve your problem.Good luck!