Skip to content
Permalink
Browse files

Fix #3838, $(document).height() incorrect in IE6

May still be broken in Netscape Navigator 4.
  • Loading branch information...
mikesherov authored and dmethvin committed Feb 25, 2012
1 parent da02e19 commit 5cae50e66e34c277412c01ccb1c24bd6a85d2d8a
Showing with 51 additions and 1 deletion.
  1. +9 −1 src/dimensions.js
  2. +17 −0 test/data/dimensions/documentLarge.html
  3. +11 −0 test/data/dimensions/documentSmall.html
  4. +14 −0 test/unit/dimensions.js
@@ -42,8 +42,16 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
if ( elem.nodeType === 9 ) {
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
doc = elem.documentElement;

// when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
// so we can't use max, as it'll choose the incorrect offset[Width/Height]
// instead we use the correct client[Width/Height]
// support:IE6
if ( doc[ clientProp ] >= doc[ scrollProp ] ) {

This comment has been minimized.

Copy link
@jdalton

jdalton Mar 8, 2012

Member

Your code comment mentions offset and client but your code in the if statement checks clientProp and scrollProp instead of clientProp and offsetProp. Is the mixup intentional?

This comment has been minimized.

Copy link
@mikesherov

mikesherov Mar 8, 2012

Author Member

window > document is meant to be clientProp > scrollProp. In this case, choose clientProp. If we didn't do this, IE6 would choose offsetProp, which includes the HTML elements default top margin of 2px.

Is that any clearer?

This comment has been minimized.

Copy link
@jdalton

jdalton Mar 8, 2012

Member

ya +1 for clearer code comment :D

This comment has been minimized.

Copy link
@mikesherov

mikesherov Mar 8, 2012

Author Member

/s/window > document/clientProp > scrollProp

return doc[ clientProp ];
}

return Math.max(
doc[ clientProp ],
elem.body[ scrollProp ], doc[ scrollProp ],
elem.body[ offsetProp ], doc[ offsetProp ]
);
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
width: 1000px;
height: 1000px;
}
</style>
</head>
<body>
<div>
<script src="../include_js.php"></script>
</div>
</body>
</html>
@@ -0,0 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<script src="../include_js.php"></script>
</div>
</body>
</html>
@@ -315,3 +315,17 @@ test("outerHeight()", function() {
div.remove();
jQuery.removeData($div[0], "olddisplay", true);
});

testIframe("dimensions/documentSmall", "window vs. small document", function( jQuery, window, document ) {
expect(2);

equal( jQuery( document ).height(), jQuery( window ).height(), "document height matches window height");
equal( jQuery( document ).width(), jQuery( window ).width(), "document width matches window width");
});

testIframe("dimensions/documentLarge", "window vs. large document", function( jQuery, window, document ) {
expect(2);

ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height");
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width");
});

0 comments on commit 5cae50e

Please sign in to comment.
You can’t perform that action at this time.