这是一个简短的测试来证明我的问题。我有一个加载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返回正确的值?
答案 0 :(得分:0)
请改为尝试:
var div = $(this).contents().find("html");