Leon's Blog

Programmer

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

main.htm:

<html> 
    <head> 
       <  http-equiv='Content-Type'  content='text/html;  charset=gb2312' /> 
       <  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com' /> 
       <title>i自适应加载的页面高度</title> 
    </head> 
    
    <body>
        <div><i src="http://10.187.202.3/child.htm"></i></div>
    </body>
</html>

child.htm:

<html> 
<head> 
    <  http-equiv='Content-Type'  content='text/html;  charset=gb2312' /> 
    <  name='author'  content='F.R.Huang(meizz梅花雪)//www.meizz.com' /> 
    <title>i  自适应其加载的网页(多浏览器兼容)</title> 
    < type="text/java">
    <!--
    iAutoFit()
    {
        try
        {
            if(window!=parent)
            {
                var a = parent.getElementsByTagName("I");
                for(var i=0; i<a.length; i++) //author:meizz
                {
                    if(a[i].contentWindow==window)
                    {
                        var h1=0, h2=0;
                        a[i].parentNode.style.height = a[i].offsetHeight +"px";
                        a[i].style.height = "10px";
                        if(documentElement&&documentElement.scrollHeight)
                        {
                            h1=documentElement.scrollHeight;
                        }
                        if(body) h2=body.scrollHeight;

                        var h=Math.max(h1, h2);
                        if(all) {h += 4;}
                        if(opera) {h += 1;}
                        a[i].style.height = a[i].parentNode.style.height = h +"px";
                    }
                }
            }
        }
        catch (ex){}
    }
    if(attachEvent)
    {
        attachEvent("",  iAutoFit);
        //attachEvent("onresize",  iAutoFit);
    }
    else if(addEventListener)
    {
        addEventListener('load',  iAutoFit,  false);
        //addEventListener('resize',  iAutoFit,  false);
    }
    //-->
    </> 
</head> 
<body>
    <table border="1" width="200" style="height: 400px; background-color: yellow">
        <tr>
            <td>i  自适应其加载的网页(多浏览器兼容,支持XHTML)</td>
        </tr>
    </table>
</body> 
</html>

posted on 2007-09-03 11:53  疯蜂  阅读(131)  评论(0编辑  收藏  举报