<iframe id="myframe" name="myframe" width="566px" frameBorder="0" src="" runat="server"></iframe>
iframe 加上runat="server"了,因为我在后台要改变myframe的src,找了很多自适应高度的js但是不能用啊,一般都Onload=jvascript:SetHeight(this), 关键是加了ruant="server" 不能用onload事件了,请教下还有什么办法能使iframe自适应高度?

解决方案 »

  1.   

    你可以在body里面写onload
    把iframe的ID传进去
      

  2.   

    写了,试了很多方法都不行,只有onload="javascript:SetWinHeight(this)", 把this传过去的时候可以
      

  3.   

    <iframe id="myframe" name="myframe" width="566px" frameBorder="0" src="default.aspx" onload="Javascript:SetWinHeight(this)"></iframe>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+100;
    }
    }
    }
    就这样的时候可以,然后我改了不用onload,把js代码放到iframe下面去也不行...试了半天了就不行..
      

  4.   

    http://cyanopal.blog.hexun.com/8366113_d.html这个行么
      

  5.   

    <script type="text/javascript">
            function SetCwinHeight()
            {
                try{
                    var bobo=document.getElementById("ifram123"); //iframe id
                    if (document.getElementById)
                    {
                        if (bobo && !window.opera)
                        {
                            if (bobo.contentDocument && bobo.contentDocument.documentElement.offsetHeight)
                            {
                                bobo.height = bobo.contentDocument.documentElement.offsetHeight+40;
                            }
                            else if(bobo.Document && bobo.Document.body.scrollHeight)
                            {
                                bobo.height = bobo.Document.body.scrollHeight+40;//40是空白,可根据需要自己改
                            }
                        }
                    }
                }catch(err)
                {}
            }
            </script>
      
           <iframe id="ifram123" scrolling="no" height="500" src="default.aspx" onload="SetCwinHeight()" width="100%"   style="border:0px; " frameborder="0">
        
             </iframe> 
      

  6.   

    这个更不行了 我都说过了 不能 onload  iframe是服务器端控件了 
      

  7.   


    iframe 这个没必要加  RUNAT=“SERVER ”吧
      

  8.   


    我要在后台改iframe的src啊....
      

  9.   

    你把 后台 需要改SRC的地方给我看看  
      

  10.   

            if (!IsPostBack)
            {
                if (Request["frame"] == null)
                {
                    myframe.Attributes.Add("src", "Default.aspx");
                }
                else
                {
                    string src = Request["frame"].ToString();
                    myframe.Attributes.Add("src", src);
                }
            }
      

  11.   

    <script type="text/javascript"> 
            function SetCwinHeight() 
            { 
                try{ 
                    var bobo=document.getElementById("ifram123"); //iframe id 
                    if (document.getElementById) 
                    { 
                        if (bobo && !window.opera) 
                        { 
                            if (bobo.contentDocument && bobo.contentDocument.documentElement.offsetHeight) 
                            { 
                                bobo.height = bobo.contentDocument.documentElement.offsetHeight+40; 
                            } 
                            else if(bobo.Document && bobo.Document.body.scrollHeight) 
                            { 
                                bobo.height = bobo.Document.body.scrollHeight+40;//40是空白,可根据需要自己改 
                            } 
                        } 
                    } 
                }catch(err) 
                {} 
            } 
            </script> 
      
          <iframe id="ifram123" scrolling="no" height="500" src="<%= getsrc()%>" onload="SetCwinHeight()" width="100%"  style="border:0px; " frameborder="0"> 
        
            </iframe> CS文件 里写方法public string getsrc()
    {string result="";
     if (Request["frame"] == null) 
                { 
                  result="Default.aspx"; 
                } 
                else 
                { 
                   result= Request["frame"].ToString(); 
                            } 
    return result;}
      

  12.   

    我试过了,也不行啊,src="javascript:getSrc()"这样的话页面就一直刷新,关都关不了,我也不清楚为什么这样,不信你一会远程看看...