我现在要在我的网站里加上别iframe,引用别人的网页,现在问题是子页面的内容并不固定(高度不固定),而我现在要在我的父页面里面使IFrame嵌套过来的网页自动适应其高度。请问我这个怎么搞:
这种方法并不适合我,具体请看后面连接的网页:http://www.ccvita.com/376.html 
请注意:这里子页面是别人的页面,我并不能在子页面添加代码,也就是说只能在父页面(我自己的网站)里面改动。

解决方案 »

  1.   

    那可以先获取子页面的  高度 或宽度  用js  
    然后再父页面设子iframe的高度和宽度
      

  2.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
    <html> 
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=GBK" /> 
            <title>a</title> 
        </head> 
        <body> 
            <div style="border:1px dotted;width:400px"> 
                <iframe id="frame_content" src="iframe_b.html" scrolling="no" frameborder="0" onload="this.height=100"></iframe> 
            </div> 
            <div><button onclick="checkHeight()">Check Height</button></div> 
            <script type="text/javascript"> 
                function reinitIframe(){
                    var iframe = document.getElementById("frame_content");
                    try{
                        var bHeight = iframe.contentWindow.document.body.scrollHeight;
                        var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
                        var height = Math.max(bHeight, dHeight); //max()
                        iframe.height =  height;
                    }catch (ex){}
                }
                window.setInterval("reinitIframe()", 200);
                
                function checkHeight() {
                    var iframe = document.getElementById("frame_content");
                    var bHeight = iframe.contentWindow.document.body.scrollHeight;
                    var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
                    alert("bHeight:" + bHeight + ", dHeight:" + dHeight);
                }
            </script> 
        </body> 
    </html> 不断调整height   主要用到max setInterval 占用的资源几乎可以忽略不计。
      

  3.   

    iframe.contentWindow.document.body.scrollHeight
    这句能执行吗? 是没有权限吧