Iframe 它的高度如何控制?

解决方案 »

  1.   

    固定:height="100px"也可以通过js来动态修改,就是修改height属性
      

  2.   

      main.htm的代码:   
      <iframe   src=page.htm id="PageIframe"></iframe>   
        
      page.htm的代码:   
      <script>   
      function   resize()   
      {parent.document.all.PageIframe.height=document.body.scrollHeight;}   
      </script>   
      <body onload="resize()">   
      </body>
      

  3.   

    document.getElementById(iframeID).height = '100px';
      

  4.   

    自动调整高度<script>
    function autoResize()
    {
    try
    {
    document.all["content"].style.height=content.document.body.scrollHeight
    }
    catch(e){}
    }
    </script>
    <iframe src="main.htm" name="content" id="content" scrolling="no" frameborder="0" width="100%" onload="autoResize();"></iframe>
      

  5.   

    给你一段自适应高度的代码
    <iframe src='public_detailMain.asp' width="100%" height="100%" id='dd' name="dd" scrolling=no scroll="auto" border="0" noresize frameborder="0" marginheight=1 marginwidth=1></iframe>public_detailMain.asp 的页面
    <body onload="parent.document.all.dd.style.height=document.body.scrollHeight">
      

  6.   

    <iframe id="testFrame" width=100% height=500px></iframe>
      

  7.   

    如果是想根据iframe中的内容,自动调整iframe的高度,可以使用脚本来控制:
    <script language="javascript" type="text/javascript">           
     //高度自适应  
         function frame()
         {
        var fmheight =1000;
        var win=document.getElementById("iframe的ID");//
        try
        {
            if (win.contentDocument && win.contentDocument.body.offsetHeight) 
                    fmheight = win.contentDocument.body.offsetHeight; 
                else if(win.Document && win.Document.body.scrollHeight)
                    fmheight = win.Document.body.scrollHeight;
        }
        catch(e){}
        win.height = fmheight;
        }
        </script>
    然后在iframe中使用onload方法加载这个函数就可以了
      

  8.   

     <iframe id="Iframe1" runat="server" frameborder="0" scrolling="no" 
     style="width: 180px; height: 140px">
    </iframe>