繁体   English   中英

jQuery报告Firefox iframe中的元素高度不正确

[英]jQuery reports incorrect element height in Firefox iframe

这里有一个简短的测试来演示我的问题。 我有一个加载iframe的页面:

<html>
    <head>
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
    </head>
    <body>
        <iframe id="iframe" src="box.html" style="width: 100px; height: 100px"></iframe>
        <script>
            $('#iframe').bind('load', function () {
                var div = $(this).contents().find('div');
                alert(div.height());
                alert(div.innerHeight());
                alert(div.outerHeight());
                alert(div.outerHeight(true));
            });
        </script>
    </body>
</html>

iframe(box.html)包含单个样式的div:

<html>
    <head>
        <title></title>
        <style>
            div {
                height: 50px;
                width: 50px;
                margin: 5px;
                padding: 5px;
                border: 2px solid #00f;
                background-color: #f00;
            }
        </style>
    </head>
    <body>
        <div></div>
    </body>
</html>

四个警报应分别返回50、60、64和74。 可以在Safari和Chrome中正常运行。 在FF 3.5.1中,它们都返回64。这是错误的。

有谁知道我可以如何强制FF / jQuery返回正确的值?

尝试以下方法:

var div = $(this).contents().find("html");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM