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
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
I was able to duplicate the bug in Chrome 7.0.517.24 beta. Safari, however,
appears to behave correctly.
My mistake . . . Safari does have the same functionality. I made a mistake
on my first test.
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.
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.
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.
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.
In Chromium 11.0.696.0 bug is not fixed. :(
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";
}
The previous suggestion of textArea.scrollHeight-4 works for me too. This
workaround works in Chrome, IE, and FF for me.
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
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;
}