Issue 34224 in chromium: Incorrect scrollWidth and scrollHeight on the <body> element

684 views
Skip to first unread message

chro...@googlecode.com

unread,
Feb 2, 2010, 7:40:31 AM2/2/10
to chromi...@chromium.org
Status: Unconfirmed
Owner: ----
Labels: Type-Bug Pri-2 Area-Undefined

New issue 34224 by pcxunlimited: Incorrect scrollWidth and scrollHeight on
the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

Chrome Version : 4.0.302.2 (Official Build 36665) dev
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari 4: Don't know
Firefox 3.x: OK
IE 7: Don't know
IE 8: Don't know

What steps will reproduce the problem?
1. Read the clientWidth/Height and scrollWidth/Height properties on the
<body> element.

What is the expected result?
They should be correct, as per the MDC:
https://developer.mozilla.org/en/DOM/element.scrollWidth
https://developer.mozilla.org/En/DOM:element.scrollHeight

What happens instead?
scrollWidth and scrollHeight are larger than clientWidth and clientHeight,
even when scrollbars are not present.

Please provide any additional information below. Attach a screenshot if
possible.
You can find a reduced test-case here:
http://paaru.pbworks.com/f/Scroll%20Test.html

Basically, if there's no scrollbars, scrollWidth and scrollHeight should be
the same as clientWidth and clientHeight. In the reduced test case, you can
see that is not the case. Firefox 3.0 reports correct numbers, but Chrome
does not. This makes it impossible to determine if there are scrollbars on
the <body> element, breaking functionality in an extension of mine.

I assume this is a bug with WebKit, but I have not been able to test
Safari, so I don't know. In addition, this may affect elements other than
<body>, but <body> was the most obvious one.

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

chro...@googlecode.com

unread,
Feb 19, 2010, 5:08:11 PM2/19/10
to chromi...@chromium.org

Comment #2 on issue 34224 by ssil...@stormsilver.net: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

I have this problem as well. I have a loop which attempts to adjust the
iframe's height via:

iframe.contentWindow.document.getElementsByTagName('body')[0].scrollHeight

In my case, the iframe's height should be in the neighborhood of 125px, but
is incorrectly being reported
anywhere in the range of 200-450px. This loop fires every 150ms or so, and
the height is eventually reported
correctly after 5-10 loops. I am curious why the height would initially be
so large, because the div containing
the iframe is sized at 0px high.

Chrome 5.0.307.9 beta (Mac 10.6, Ubuntu 9.10): FAIL
Safari 4.0.4 nightly 6531.21.10, r54921 (Mac 10.6): FAIL
Safari 3.2.2 525.28.1 (Win XP): FAIL
Firefox 3.0.18 (Win XP): OK
Firefox 3.5.8 (Mac 10.6, Ubuntu 9.10): OK
Firefox 3.6.0 (Mac 10.6): OK
IE6 (Win XP): OK
IE7 (Win XP): OK
IE8 (Win XP): OK

chro...@googlecode.com

unread,
Oct 5, 2010, 1:23:47 AM10/5/10
to chromi...@chromium.org

Comment #3 on issue 34224 by ajdaniels5: Incorrect scrollWidth and

I was able to duplicate the bug in Chrome 7.0.517.24 beta. Safari, however,
appears to behave correctly.

chro...@googlecode.com

unread,
Oct 5, 2010, 1:27:50 AM10/5/10
to chromi...@chromium.org

Comment #4 on issue 34224 by ajdaniels5: Incorrect scrollWidth and

My mistake . . . Safari does have the same functionality. I made a mistake
on my first test.

chro...@googlecode.com

unread,
Oct 11, 2010, 4:19:48 AM10/11/10
to chromi...@chromium.org

Comment #5 on issue 34224 by dersiedl...@gmx.de: Incorrect scrollWidth and

I have this problem as well, but not only for the body tag, but as well for
a textarea.
Problem: height of textarea set to 150px and even when there are no
scrollbars the scrollHeight is reported to be 154px and the offsetHeight to
be 158px.

chro...@googlecode.com

unread,
Nov 29, 2010, 6:13:43 PM11/29/10
to chromi...@chromium.org

Comment #7 on issue 34224 by guillaume.gobbe: Incorrect scrollWidth and

Same problem on chrome 7.0.517.44

Hope it will be soon corrected because I use it to adjust an iframe height
but it fail on Chrome (it is bigger than the correct value).

In Firefox and IE 9 (beta) it works fine.

chro...@googlecode.com

unread,
Dec 3, 2010, 5:49:22 AM12/3/10
to chromi...@chromium.org

Comment #8 on issue 34224 by pavel.gabor: Incorrect scrollWidth and

I have tested new version of Chrome (8.0.522.215) and bug still exists. I
would really appreciate if someone would give me feedback on issue. When do
you plan to correct it or maybe guides to create workaround to correct this
issue.

chro...@googlecode.com

unread,
Dec 6, 2010, 9:48:44 AM12/6/10
to chromi...@chromium.org

Comment #9 on issue 34224 by dersiedl...@gmx.de: Incorrect scrollWidth and

my workaround is to check the browser and if it is webkit i set a height
correction.

if ($.browser.webkit) {
heightCorrection = 4;
}

maybe this helps someone.

chro...@googlecode.com

unread,
Mar 9, 2011, 11:42:20 AM3/9/11
to chromi...@chromium.org

Comment #10 on issue 34224 by bigbr...@gmail.com: Incorrect scrollWidth and

In Chromium 11.0.696.0 bug is not fixed. :(

chro...@googlecode.com

unread,
Aug 1, 2011, 2:30:09 AM8/1/11
to chromi...@chromium.org

Comment #17 on issue 34224 by jrlagard...@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

I had the same issue trying to resize a textarea so the text fits inside it
without using scrollbars. I solved the problem by substracting 4 whenever
the height increased by that amount, if the height changes by any other
amount it is because the user filled in more text that fits in the current
area. The code was:

var writer = document.getElementById("textArea"); //Textarea where user
will post
var scroll = writer.scrollHeight;

function write() { //called with an onkeyup event
if ( (scroll+4) == writer.scrollHeight) {
scroll = writer.scrollHeight - 4;
} else { scroll = writer.scrollHeight; }
writer.style.height = scroll + "px";
}

chro...@googlecode.com

unread,
Aug 5, 2011, 6:55:32 PM8/5/11
to chromi...@chromium.org

Comment #18 on issue 34224 by Clark.W...@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

The previous suggestion of textArea.scrollHeight-4 works for me too. This
workaround works in Chrome, IE, and FF for me.

chro...@googlecode.com

unread,
Apr 5, 2012, 3:45:03 AM4/5/12
to chromi...@chromium.org

Comment #21 on issue 34224 by fredrik....@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

After trying various workarounds with plugins etc I just accepted it is
impossible to gi via the body element and wrote this script where I check
the max scrollheight of any element of type div, table or form within the
framed page, works like a charm in ff, chrome safari and IE

function resizeIframe() {

var ifrm = document.getElementById("iframe_name");

var currMax = 0;

var elementArr = new Array("div", "table", "form");//Possible
to add more elements...

for (var i = 0; i < elementArr.length; i++) {

var tempArr =
ifrm.contentWindow.document.getElementsByTagName(elementArr[i]);

for (var j = 0; j < tempArr.length; j++) {

if (tempArr[0].scrollHeight > currMax)
currMax = tempArr[0].scrollHeight;
}
}

ifrm.height = currMax + 50;

}

/Fredrik

chro...@googlecode.com

unread,
Apr 5, 2012, 9:32:20 AM4/5/12
to chromi...@chromium.org

Comment #22 on issue 34224 by fredrik....@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

Make a reference to jQuery and then do the following. Works flawlessly in
ff, chrome IE

function resizeIframe() {

var ifrm = document.getElementById("frame_name");
ifrm.height =
parseInt($("#frame_name").contents().find("body").css("height")) + 25;

}

chro...@googlecode.com

unread,
Jan 16, 2013, 6:50:11 PM1/16/13
to chromi...@chromium.org

Comment #23 on issue 34224 by shalinik...@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

add resize: none; and padding: 0 works for chrome

chro...@googlecode.com

unread,
Jan 16, 2013, 6:51:11 PM1/16/13
to chromi...@chromium.org

Comment #24 on issue 34224 by shalinik...@gmail.com: Incorrect scrollWidth

chro...@googlecode.com

unread,
Apr 11, 2013, 6:34:10 AM4/11/13
to chromi...@chromium.org

Comment #28 on issue 34224 by spawli...@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

What is going on with this issue ?
The same in Chrome 26 - ScrollHeight different than ClientHeight even
though scrolling="no"

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

chro...@googlecode.com

unread,
May 9, 2013, 12:38:50 PM5/9/13
to chromi...@chromium.org

Comment #29 on issue 34224 by yatinsha...@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

The issue still exists... I've chrome version 'Version 26.0.1410.64 m'

chro...@googlecode.com

unread,
Jun 18, 2013, 2:42:36 AM6/18/13
to chromi...@chromium.org

Comment #30 on issue 34224 by WongMing...@gmail.com: Incorrect scrollWidth
and scrollHeight on the <body> element
http://code.google.com/p/chromium/issues/detail?id=34224

The problem still exists! Google please fix it!

chro...@googlecode.com

unread,
Aug 7, 2013, 8:16:59 AM8/7/13
to chromi...@chromium.org

Comment #31 on issue 34224 by et...@nifti.com: Incorrect scrollWidth and
Here is a workaround that did the trick for me:

if ($("element being checked for scroll")[0].scrollHeight >
$(document).height()) {

} else {

chro...@googlecode.com

unread,
Jul 9, 2015, 3:16:41 AM7/9/15
to chromi...@chromium.org
Updates:
Cc: rby...@chromium.org
Labels: -Cr-Blink Cr-Blink-Scroll Hotlist-Interop

Comment #33 on issue 34224 by tk...@chromium.org: Incorrect scrollWidth and
scrollHeight on the <body> element
https://code.google.com/p/chromium/issues/detail?id=34224

(No comment was entered for this change.)

--
Reply all
Reply to author
Forward
0 new messages