Skip to content

Commit 5cae50e

Browse files
mikesherovdmethvin
authored andcommitted
Fix jquery#3838, $(document).height() incorrect in IE6
May still be broken in Netscape Navigator 4.
1 parent da02e19 commit 5cae50e

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

src/dimensions.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
4242
if ( elem.nodeType === 9 ) {
4343
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
4444
doc = elem.documentElement;
45+
46+
// when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
47+
// so we can't use max, as it'll choose the incorrect offset[Width/Height]
48+
// instead we use the correct client[Width/Height]
49+
// support:IE6
50+
if ( doc[ clientProp ] >= doc[ scrollProp ] ) {
51+
return doc[ clientProp ];
52+
}
53+
4554
return Math.max(
46-
doc[ clientProp ],
4755
elem.body[ scrollProp ], doc[ scrollProp ],
4856
elem.body[ offsetProp ], doc[ offsetProp ]
4957
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<style>
6+
body {
7+
width: 1000px;
8+
height: 1000px;
9+
}
10+
</style>
11+
</head>
12+
<body>
13+
<div>
14+
<script src="../include_js.php"></script>
15+
</div>
16+
</body>
17+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
</head>
6+
<body>
7+
<div>
8+
<script src="../include_js.php"></script>
9+
</div>
10+
</body>
11+
</html>

test/unit/dimensions.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,17 @@ test("outerHeight()", function() {
315315
div.remove();
316316
jQuery.removeData($div[0], "olddisplay", true);
317317
});
318+
319+
testIframe("dimensions/documentSmall", "window vs. small document", function( jQuery, window, document ) {
320+
expect(2);
321+
322+
equal( jQuery( document ).height(), jQuery( window ).height(), "document height matches window height");
323+
equal( jQuery( document ).width(), jQuery( window ).width(), "document width matches window width");
324+
});
325+
326+
testIframe("dimensions/documentLarge", "window vs. large document", function( jQuery, window, document ) {
327+
expect(2);
328+
329+
ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height");
330+
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width");
331+
});

0 commit comments

Comments
 (0)