From 5cae50e66e34c277412c01ccb1c24bd6a85d2d8a Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Sat, 25 Feb 2012 13:13:16 -0500 Subject: Fix #3838, $(document).height() incorrect in IE6 May still be broken in Netscape Navigator 4. --- src/dimensions.js | 10 +++++++++- test/data/dimensions/documentLarge.html | 17 +++++++++++++++++ test/data/dimensions/documentSmall.html | 11 +++++++++++ test/unit/dimensions.js | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/data/dimensions/documentLarge.html create mode 100644 test/data/dimensions/documentSmall.html diff --git a/src/dimensions.js b/src/dimensions.js index 8069676eb..64da9f4f2 100644 --- a/src/dimensions.js +++ b/src/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 ] ) { + return doc[ clientProp ]; + } + return Math.max( - doc[ clientProp ], elem.body[ scrollProp ], doc[ scrollProp ], elem.body[ offsetProp ], doc[ offsetProp ] ); diff --git a/test/data/dimensions/documentLarge.html b/test/data/dimensions/documentLarge.html new file mode 100644 index 000000000..8b434e719 --- /dev/null +++ b/test/data/dimensions/documentLarge.html @@ -0,0 +1,17 @@ + + + + + + + +
+ +
+ + \ No newline at end of file diff --git a/test/data/dimensions/documentSmall.html b/test/data/dimensions/documentSmall.html new file mode 100644 index 000000000..e0e9a3d54 --- /dev/null +++ b/test/data/dimensions/documentSmall.html @@ -0,0 +1,11 @@ + + + + + + +
+ +
+ + \ No newline at end of file diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 222459f51..c6b8e835c 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -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"); +}); -- cgit v1.2.3