日期:2014-05-20  浏览次数:20835 次

iframe自动适应高度!!
从网上找了一推,到最后还是低头而归!不管怎么设置,都不行,求各位大神指点!
C# code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
     <script type="text/javascript">
   function sizeChange() 
{ 
window.status=AAA.document.body.scrollHeight; 
document.all.AAA.height=AAA.document.body.scrollHeight; 

} 
   </script>
</head>
<body>
    <form id="form1" runat="server">
    <!--如果是这样,直接套用自己根目录的地址就可以-->
    <IFRAME id="AAA" src='GetCoreByClick.aspx' frameBorder=0 width="100%" scrolling=no onload="javascript:sizeChange();" > </IFRAME>
    <!---可我现在想这样,直接运用网站地址,这样就不自动适应高度了-->
   <%--<IFRAME id="AAA" src='http://www.sina.com.cn/' frameBorder=0 width="100%" scrolling=no onload="javascript:sizeChange()" > </IFRAME>--%>
    </form>
</body>
</html>


如果各位愿意帮忙,请测试后发代码,网上的代码基本上我都找遍了,未找到合适的!谢谢

注释:src必须是网站地址,例如http://www.sina.com.cn

------解决方案--------------------
不能跨域的。你必须是同一个网站的
------解决方案--------------------
没有啊,你嵌入别人的网站没用,要是都是你自己的,你可以设置嵌入的页面的大小与你的调用页面一致就可以了
------解决方案--------------------
这个可以试试,我一直在用
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>后台管理系统</title>
        <style type="text/css">.navPoint {color: white; cursor: hand; font-family: Webdings; font-size: 9pt}</style>
        <script language="JavaScript" type="text/javascript">
      if (window.screen) {
        var aw = screen.availWidth;
        var ah = screen.availHeight;
        window.moveTo(-3, -3);
        window.resizeTo(aw+7, ah+7);
//        
      }
      
function switchSysBar()
{
    if(switchPoint.innerText==3){
        switchPoint.innerText=4
        document.all("frmTitle").style.display="none"
    }else{
        switchPoint.innerText=3
        document.all("frmTitle").style.display=""
    }
}
    </script>
    </head>    
    <body style="margin: 0px;overflow:hidden; height:100%;">    
    
    <form id="form1" runat="server">    
        <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
              <tr>
                <td align="center" nowrap valign="top" id="frmTitle" height="100%">
                    <iframe id="Left" name="Left" src="MainMenu.aspx"   scrolling="auto" frameborder="0" style="width:171px;height:100%"  > </iframe>
            </td>
                   <td style="width: 9pt" height="100%" id="cc">
                        <table border="0" cellpadding="0" cellspacing="0" height="100%" bgcolor="#66CC66">
                              <tr style="cursor:hand;">
                                <td id="qh" style="HEIGHT: 100%; width: 13px;" onclick="switchSysBar()" title="点击关闭/打开左栏">
                                    <font style="FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff">
                                      <br/>
                                    <br/>
                                    <br/>
                                     屏幕切换<br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <span class="navPoint" id="switchPoint" title="点击关闭/打开左栏">3</span><br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    屏幕切换<br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                    <br/>
                                  </font></td>
                          </tr>
                  </table>
                  </td>
                  <td height="100%" width="100%" valign="top">
                        <iframe frameborder="0" id="Right" name="Right" scrolling="yes" src="Main.aspx"  style="width:100%;height:100%;" > </iframe>
                    </td>
           </tr>
        </table>
        </form>
        <script>
             function setAutoHeight(iframeElement,  dheight) {

            iframeElement.style.height =dheight ;            

            // 或者
             //iframeElement.height = iframeWindow.document.body.offsetHeight ;
             //iframeElement.width  =  iframeWindow.document.body.offsetWidth;
             
       }
        </script>
                          
        <script type="text/javascript">
            if(window.screen.width<1024){switchSysBar()}
            
//调用函数setAutoHeight();
        //document.getElementById("cc").style.height=document.body.scrollHeight;
        setAutoHeight(document.getElementById("Left"), window.document.documentElement.clientHeight +"px");
        setAutoHeight(document.getElementById("Right"), window.document.documentElement.clientHeight +"px");
        document.getElementById("qh").style.height=window.document.documentElement.clientHeight +"px";
        //alert(window.document.documentElement.clientHeight);
        </script>
        
        
    </body>
</html>