]> source.dussan.org Git - jquery.git/commitdiff
Fix #3838, $(document).height() incorrect in IE6
authorMike Sherov <mike.sherov@gmail.com>
Sat, 25 Feb 2012 18:13:16 +0000 (13:13 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 2 Mar 2012 16:45:30 +0000 (11:45 -0500)
May still be broken in Netscape Navigator 4.

src/dimensions.js
test/data/dimensions/documentLarge.html [new file with mode: 0644]
test/data/dimensions/documentSmall.html [new file with mode: 0644]
test/unit/dimensions.js

index 8069676eb204d6a861292a952b42517f2e2666e2..64da9f4f20801e1a1b9e0c9411e6f4d79e1feff8 100644 (file)
@@ -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 (file)
index 0000000..8b434e7
--- /dev/null
@@ -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>
\ No newline at end of file
diff --git a/test/data/dimensions/documentSmall.html b/test/data/dimensions/documentSmall.html
new file mode 100644 (file)
index 0000000..e0e9a3d
--- /dev/null
@@ -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>
\ No newline at end of file
index 222459f51c8c6ec678162da21cf050c229bc54d9..c6b8e835c163283d8c82d25e5c6fcafd42eb6445 100644 (file)
@@ -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");
+});