English 中文(简体)
IE/Firefox/Safari计算IE/Firefox/Safari的自动电离层——正确方式是什么?
原标题:Calculating automatic IFrame height in IE/Firefox/Safari - what is the correct way?
  • 时间:2009-08-30 11:54:50
  •  标签:

I ve browsed through many websites and in here, and could not find a final answer as each one has its errors. I need to have an automatic IFrame height, meaning if the content changes, the Iframe must adapt its height to the content. For this I need to see how to get the correct content height?

As I understand the most correct way is to use : document.getElementById( myIframe ).style.pixelHeight = document.getElementById( myIframe ).contentWindow.document.body.scrollHeight;

然而,所有浏览器的工作都是正确的。 在IE,我发现身高太小(大约8个奶粉的高度低于应有的高度)。 在减少内容量时,停机坪总会减少。 此外,它还在Safari开展工作。

因此,就最后的问题而言,什么是最正确的,什么是证明是使内容达到顶峰的最为有效的方法——应该确定“综合框架”的高度?

Thanks, Tal.

问题回答

IE问题可能是frame Border。 当你在独立实体中确定一线高度时,这包括几个特殊边界的图象。 边界线不算是边界安全局的正常边界,可以轻易从文字上排除。

您可以在独立实体中增加几张颜料,以补偿边界框架,或写:

<iframe frameborder="0">

关闭边框(如果您确实希望在框架周围有一个真正的边框,则可以使用CSS添加新边框)。

文件: 在某些情况下,体重不能与文件高度吻合:

  1. 如果iframe中的文件体有差值(如身体缺损)。 body 体积为0。

  2. 如果你在基茨模式上工作,那就是一个文件。 该机构代表了观察所的一些方面,你通常只能看到这一点。 文件 内容。 在这样的情况下,单体高度直接设定了记号高度。 然后,该机构将报告。 由此可见,iframe将不会缩小到最低层。

你们应永远使用标准模式。 如果你必须支持基尔斯模式的网页,你可以尝试整整页一页,并读出被抵消的纸。 这一点。

“Safari”问题可能由使用“CixelH”造成,这是“IE”延伸。 1. 先期使用:

style.height= number+ px ;

这是一种新鲜的黑板;如果是专门设计的,不会对文件篇幅做出反应。 考虑使用诸如服务器上模版的内容等页内的内容,或在使用自动自动自动备用金时被拖走。

$( document ).ready(function() { $( $("#msgContainer")[0].contentWindow ).load(function() {

        var offsetH = "";
        #if(!$request.userAgent.isIE())
            offsetH = $("#msgContainer")[0].contentWindow.document.body.offsetHeight;
        #else
            offsetH = $("#msgContainer")[0].contentWindow.document.body.scrollHeight;
        #end

        var minH = $($("#msgContainer")[0]).css( min-height );
        var height = $($("#msgContainer")[0]).css( height );

        if(offsetH > 250 ){
            $($("#msgContainer")[0]).css( min-height ,  250px );
            $($("#msgContainer")[0]).css( height ,  250px );
        }else{
            $($("#msgContainer")[0]).css( min-height , offsetH);
            $($("#msgContainer")[0]).css( height , offsetH);
        }
        console.log( offsetH + " : " + minH + " : " + height);
    });
});




相关问题
热门标签