0

这里有一个简短的测试来证明我的问题。我有一个加载 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 返回正确的值?

4

1 回答 1

0

试试这个:

var div = $(this).contents().find("html");
于 2012-02-27T17:02:25.680 回答