我想要的效果是不Frame高度随其内容的变化而变化,不出现滚动条.网上好多关于Iframe的,frame的不知如何来实现(高度总受到浏览器的限制)?

解决方案 »

  1.   

    function iframeAutoFit()
    {
        var ex;
    try
    {
        if(window!=parent)
        {
        var a = parent.document.getElementsByTagName("IFRAME");
        for(var i=0; i<a.length;i++){
            if(a[i].contentWindow==window)
            {
                var h1=0, h2=0;
                if(document.documentElement && document.documentElement.scrollHeight)
                {
                    h1=document.documentElement.scrollHeight;
                }
                if(document.body) h2=document.body.scrollHeight;            var h=Math.max(h1, h2);
                if(document.all) {h += 4;}
                if(window.opera) {h += 1;}
                a[i].style.height = h +"px";
                }
            }
        }
    }
    catch (ex){}
    }
    if(self.location==top.location)
        self.location="Default.aspx";
    if(document.attachEvent)
    {
        window.attachEvent("onload", iframeAutoFit);
        window.attachEvent("onresize", iframeAutoFit);
    }
    else
    {
        window.addEventListener('load', iframeAutoFit, false);
        window.addEventListener('resize', iframeAutoFit, false);
    }
    使用方法
     在页面底部引用这脚本
     如果需要的话在改变页面高度的时候调用iframeAutoFit()