Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery报告Firefox iframe中的元素高度不正确_Javascript_Jquery_Css_Iframe_Height - Fatal编程技术网

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

Javascript jQuery报告Firefox iframe中的元素高度不正确,javascript,jquery,css,iframe,height,Javascript,Jquery,Css,Iframe,Height,这里有一个简短的测试来证明我的问题。我有一个加载iframe的页面: <html> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script> </head> <body> &l

这里有一个简短的测试来证明我的问题。我有一个加载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");