iframe runat="server"  怎么自動適應大小?
<iframe  id="frameNavigation"  frameborder="0" runat ="server" ></iframe>我在Page_Load()
{
frameNavigation.Attributes.Add("onload", "autoResizeIframe()");
}又定義了
<script type ="text/javascript" >function autoResizeIframe()
{
document.all.frameNavigation.height="300";
//parent.frames("frameNavigation").style.height="300";
//parent.frames("frameNavigation").style.height=parent.frames("frameNavigation").document.body.scrollHeight;//window.frameNavigation.document.body.scrollHeight;
//height="300";
}</script>但運行後沒生效

解决方案 »

  1.   

    function myresize(){
    window.resizeTo(document.body.scrollWidth,document.body.scrollHeight);
    }这个是根据 iframe  调用页面的高度自动调整页面高度的,看看。
      

  2.   

    mostice(沉默的羔羊) :你這方法我試了一下,不行 倒把父窗口變化小了
      

  3.   

    把这段js加到<head>中去试一下看看 <script language=javascript>
    function f_frameStyleResize(targObj){
      var targWin=targObj.parent.document.all[targObj.name];
      if(targWin!=null){
        var HeightValue=targObj.document.body.scrollHeight;
        targWin.style.pixelHeight=HeightValue+15;
      }}
    function f_iframeResize(){
      f_frameStyleResize(self);
    }
    window.onload=f_iframeResize;
    </script>
      

  4.   

    樓上的 這段代碼放父ASPX還是IFRAME的SRC ASPX裡呀,
    另  f_frameStyleResize(self);裡的參數是self? 還是 iframe的id呀
      

  5.   

    以上方法都試過了,好像不行<script type ="text/javascript" >function autoResizeIframe()
    {
    document.all.frameNavigation.height="300";
    //parent.frames("frameNavigation").style.height="300";
    //parent.frames("frameNavigation").style.height=parent.frames("frameNavigation").document.body.scrollHeight;//window.frameNavigation.document.body.scrollHeight;
    //height="300";
    }</script>
    直接賦值都沒效哦,頂,求解決方法
      

  6.   

    <script type="text/javascript">
    function autoResizeIframe()
    {
    document.all.frameNavigation.height="200";
    }
    </script>直接写到页面底部就可以了
      

  7.   

    上面写错了,把下面这个放到页面底部就可以了
    <script type="text/javascript"> document.all.frameNavigation.height="200";
    </script>
      

  8.   

    呵。樓上的,要是寫成固定值,我直接
    <iframe  id="frameNavigation"  frameborder="0" runat ="server" height="300"></iframe>
    就行了我主要是想它能自動適應大小,
    而且現在發現放在javascript function autoResizeIframe()裡,就是賦它固定值好像也沒效,好像這個函數沒有執行一樣
      

  9.   

    在後臺是這樣設置IFRAME的SRC    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {        frameNavigation.Attributes["src"] = "frmMakeScheduleDetail.aspx?iordno=" + ((GridView)sender).SelectedRow.Cells[2].Text; 
        }
      

  10.   

    function autoResizeIframe()
    {
    document.all.frameNavigation.style.height="300";
    }
      

  11.   

    sp1234(满城尽是意淫女——如果百度收购腾讯,市场战胜技术) :
    還是不行
    如果直接<iframe  id="frameNavigation"  frameborder="0" runat ="server" onload="autoResizeIframe()"></iframe>
    在編譯是出錯,說是找不到autoResizeIframe()這個東東,估計編譯是在找後臺的這個過程但
    frameNavigation.Attributes.Add("onload", "autoResizeIframe()");
    又看不到效果,不知道到底有沒有執行autoResizeIframe()
    但查看源代碼裡面就有
    <iframe id="ctl00_ContentPlaceHolder1_frameNavigation" frameborder="0" onload="autoResizeIframe()" src="frmMakeScheduleDetail.aspx?iordno=0610003"></iframe>鬱悶
      

  12.   

    你的代码只有这一行可执行,你的代码显示出你的意思根本不是什么“自适应大小”,而且你在后边也说要直接设置高度。对于仅仅设置高度来说,怎么不行?你试一试看:
    <html>
    <body onload="autoResizeIframe();">
    <iframe src="http://community.csdn.net/Expert/ForumList.asp?typenum=1&roomid=5202" 
    height=100 id=frameNavigation></iframe>
    <script language=javascript>
    function autoResizeIframe()
    {
    document.all.frameNavigation.style.height="300";
    }
    </script>
    </body>
    </html>
      

  13.   

    调整了一下onload的位置:<html>
    <body>
    <iframe src="http://community.csdn.net/Expert/ForumList.asp?typenum=1&roomid=5202" 
    height=100 id=frameNavigation onload="autoResizeIframe();"></iframe>
    <script language=javascript>
    function autoResizeIframe()
    {
    document.all.frameNavigation.style.height="300";
    }
    </script>
    </body>
    </html>也是行的呀?!
      

  14.   

    請加一個 runat="server" 試試<iframe src="http://community.csdn.net/Expert/ForumList.asp?typenum=1&roomid=5202" 
    height=100 id=frameNavigation runat="server"></iframe>
      

  15.   

    他说“但查看源代碼裡面就有<iframe id="ctl00_ContentPlaceHolder1_frameNavigation" frameborder="0" onload="autoResizeIframe()" src="frmMakeScheduleDetail.aspx?iordno=0610003"></iframe>”,可见runat=server是他自己的事,已经不用担心了。所以我只给出html中的写法。这里先解决“直接设置高度”的问题。这个都做不好,还怎么“自适应大小”?
      

  16.   

    tianzhenjing(宁静夏天) ( ) 信誉:98    Blog  2006-12-21 10:37:50  得分: 0  
     
     
       上面写错了,把下面这个放到页面底部就可以了
    <script type="text/javascript"> document.all.frameNavigation.height="200";
    </script>
      
     
    ==================
    你把200换成<% = 后台变量 %>不就动态了?
      

  17.   

    关于所谓的“自适应”是很误导的。ie中IFrame外边不能随意操纵里边的所有属性,因此根本不能让iframe通用的自适应内容,而是里边的内容页面通过:
      parent.document.all[window.name].style.height=document.body.scrollHeight;
    来强行改变容器对自己设置的高度。
      

  18.   

    我是直接在設計模式代碼裡加上 runat="server"的,
    <iframe  id="frameNavigation"  frameborder="0" runat ="server" ></iframe>
    如果不加,在後臺代碼裡取不到frameNavigation這個控件 就是因為現在直接賦值都搞不定,所以先要搞定直接賦值,再搞 自適應請 sp1234(满城尽是意淫女——如果百度收购腾讯,市场战胜技术) 再幫手試下
      

  19.   

    照着这个例子做:<html>
    <body>
        <hr />
        <iframe src="a.htm" height="100" id="frameNavigation" name="frameNavigation" 
            scrolling="no" frameborder="0"></iframe>
        <hr />
    </body>
    </html>
    文件a.htm:
    <html>
    <body onload="parent.document.all[window.name].style.height=document.body.scrollHeight;">
        askdfaklsdfas<br />
        dfa<br />
        sdf<br />
        as<br />
        dfa<br />
        sdf<br />
        as<br />
        dfa<br />
        sdf<br />
        sssssssssssssssssssss
    </body>
    </html>
      

  20.   

    你可以看到,你的iframe对象实际上连height都不用设置,也不用设置onload客户端事件,设置了也不能起作用,我上面说了原因了,ie会认为外边的iframe没有权限读取内部的document.body.scrollHeight,以防有人嵌入javascript病毒。
      

  21.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
      
      protected void Button1_Click( object sender, System.EventArgs e )
      {
        frameleft.Attributes["Src"] = "http://dotnet.aspx.cc";  }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      

  22.   

    楼主!
    你可以看下这个帖!
    孟子老大解决的哦!
    http://community.csdn.net/Expert/topic/5245/5245033.xml?temp=.4968683
      

  23.   

    我知道如果不加 runat="server"  可以照你們的方法改變iframe的高和寬,
    如果加了runat="server" 就沒辦法了?
      

  24.   

    加了runat="server" 没有影响。
      

  25.   

    照着这个例子做:<html>
    <body>
        <hr />
        <iframe src="a.htm" height="100" id="frameNavigation" name="frameNavigation" 
            scrolling="no" frameborder="0"></iframe>
        <hr />
    </body>
    </html>
    文件a.htm:
    <html>
    <body onload="parent.document.all[window.name].style.height=document.body.scrollHeight;">
        askdfaklsdfas<br />
        dfa<br />
        sdf<br />
        as<br />
        dfa<br />
        sdf<br />
        as<br />
        dfa<br />
        sdf<br />
        sssssssssssssssssssss
    </body>
    </html>
    ===================================
    上面這段代碼我試了沒問題,但將onload="parent.document.all[window.name].style.height=document.body.scrollHeight;"放到我的SRC frmMakeScheduleDetail.aspx 中,出問題了:parent.document.all[...].style是NULL或不是一個物體我的父ASPX套用了一個主版頁面,不知跟這有沒有關係
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="frmMakeSchedule.aspx.cs" Inherits="RemoteForms_frmMakeSchedule" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">&nbsp;
    <script type ="text/javascript" src= "../CSS/calendar.js"></script>
    <div style ="vertical-align:middle  " >
      <center>
      <table border="0" width="2000" cellspacing="0" cellpadding="0" height="300">
        <tr>
          <td style="width:94%; vertical-align: middle;  text-align: left; height: 19px;">
              訂單號:<asp:TextBox ID="TxtIOrdNo" runat="server" Width="105px"></asp:TextBox>
              &nbsp; &nbsp; 客戶:<asp:DropDownList ID="DdlCusNo" runat="server">
              </asp:DropDownList>
              &nbsp; &nbsp; 工廠交期:<asp:TextBox ID="TxtHDate1" runat="server" 
                  Width="75px"></asp:TextBox>~<asp:TextBox ID="TxtHDate2" runat="server" Width="83px"></asp:TextBox>
              &nbsp; &nbsp; 是否結案:<asp:DropDownList ID="DdlChk" runat="server">
              </asp:DropDownList>
              &nbsp; &nbsp; 訂單狀態:<asp:DropDownList ID="DdlState" runat="server">
              </asp:DropDownList>
              &nbsp; &nbsp;
              <asp:Button ID="Button1" runat="server" Text="查詢" /></td> 
        </tr>
        <tr>
          <td style="width:94%; vertical-align: middle; text-align: center;height: 18px;"></td> 
        </tr>
            <tr>
          <td style="width:94%; vertical-align: top; text-align: left;">
              <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                  BorderStyle="Ridge" BorderWidth="2px" DataSourceID="SqlDataSource1" PageSize="8" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanged="GridView1_PageIndexChanged" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
                  <Columns>
                      <asp:CommandField ShowSelectButton="True">
                          <ItemStyle Wrap="False" />
                      </asp:CommandField>
                      <asp:ButtonField ButtonType="Image" Text="我知道了" />
                      <asp:BoundField DataField="訂單號碼" HeaderText="訂單號碼" ReadOnly="True" SortExpression="訂單號碼">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="序號" HeaderText="序號" SortExpression="序號">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="客戶" HeaderText="客戶" SortExpression="客戶">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="接單日期" HeaderText="接單日期" SortExpression="接單日期">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="工廠交期" HeaderText="工廠交期" SortExpression="工廠交期">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="希望交期" HeaderText="希望交期" SortExpression="希望交期">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="貨櫃尺寸" HeaderText="貨櫃尺寸" SortExpression="貨櫃尺寸">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="結關日" HeaderText="結關日" SortExpression="結關日">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="備註" HeaderText="備註" SortExpression="備註" >
                          <ItemStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="qc備註" HeaderText="qc備註" SortExpression="qc備註" >
                          <ItemStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="修改備註" HeaderText="修改備註" SortExpression="修改備註" >
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="備料" HeaderText="備料" SortExpression="備料" >
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                      <asp:BoundField DataField="是否結案" HeaderText="結案" SortExpression="是否結案">
                          <ItemStyle Wrap="False" />
                          <HeaderStyle Wrap="False" />
                      </asp:BoundField>
                  </Columns>
                  <SelectedRowStyle BackColor="Blue" ForeColor="White" />
                  <HeaderStyle BackColor="Black" ForeColor="White" />
                  <AlternatingRowStyle BackColor="#CCCCCC" />
              </asp:GridView>
              <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:smartERPIIRemoteConnectionString %>"
                  SelectCommand="up_OrdList" SelectCommandType="StoredProcedure">
                  <SelectParameters>
                      <asp:ControlParameter ControlID="TxtIOrdNo" ConvertEmptyStringToNull="False" Name="iordno"
                          PropertyName="Text" Type="String" />
                      <asp:ControlParameter ControlID="DdlCusNo" Name="cusno" PropertyName="SelectedValue"
                          Type="String" />
                      <asp:ControlParameter ControlID="TxtHDate1" Name="hdate1" PropertyName="Text" Type="DateTime" />
                      <asp:ControlParameter ControlID="TxtHDate2" Name="hdate2" PropertyName="Text" Type="DateTime" />
                      <asp:ControlParameter ControlID="DdlChk" Name="chk" PropertyName="SelectedValue"
                          Type="String" />
                      <asp:ControlParameter ControlID="DdlState" Name="state" PropertyName="SelectedValue"
                          Type="String" />
                  </SelectParameters>
              </asp:SqlDataSource>
          </td> 
        </tr>
       </table> 
       </center> 
    <iframe  id="frameNavigation"  frameborder="0" runat ="server" ></iframe>
    </div> 
    </asp:Content>在父ASPX中的GRIDVIEW1選擇事件中做如下的操作的:
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {        frameNavigation.Attributes["src"] = "frmMakeScheduleDetail.aspx?iordno=" + ((GridView)sender).SelectedRow.Cells[2].Text;
            
        }