Closed Bug 891086 Opened 12 years ago Closed 5 years ago

documentElement.scrollHeight/clientHeight documentation incorrect

Categories

(Developer Documentation Graveyard :: API: DOM, defect, P5)

x86
macOS
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: Gankra, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 Steps to reproduce: Create a blank html5 document (e.g. just <!doctype HTML>). Run the following code: console.log(window.innerHeight); console.log(document.documentElement.scrollHeight); console.log(document.body.scrollHeight); Actual results: window.innerHeight and document.documentElement.scrollHeight return the same value, and document.body.scrollHeight is 0. Expected results: window.innerHeight should be substantially larger than document.documentElement.scrollHeight, which should be 8. One can quickly confirm this is strange by inspecting the <html> element, and seeing that the rendered bounding box is only a few pixels high. The expected behaviour is the behaviour of Webkit (at very least the latest chrome/safari releases) and Firefox 21. The actual behaviour is the behaviour of IE10 and Firefox 22. Further, the MDN docs[0] describes element.scrollHeight as "If the element's content generated a vertical scrollbar, the scrollHeight value is equal to the minimum clientHeight the element would require in order to fit all the content in the viewpoint without using a vertical scrollbar. When an element's content does not generate a vertical scrollbar, then its scrollHeight property is equal to its clientHeight property." Since the html element is much smaller than the viewport, it is safe to say that it should be equal to the clientHeight, which is defined[1] as follows: "clientHeight can be calculated as CSS height + CSS padding - height of horizontal scrollbar (if present)." Inspecting the computed height and padding shows that this should equal 8, and not the size of the whole viewport. It is possible that the documentElement is simply considered a special case for client/scrollHeight. If so, then at very least this should be documented. [0]: https://developer.mozilla.org/en-US/docs/Web/API/element.scrollHeight [1]: https://developer.mozilla.org/en-US/docs/Web/API/element.clientHeight
Component: Untriaged → DOM
Product: Firefox → Core
> It is possible that the documentElement is simply considered a special case for > client/scrollHeight. It is, in standards mode. See http://dev.w3.org/csswg/cssom-view/#dom-element-scrollheight and http://dev.w3.org/csswg/cssom-view/#dom-element-clientheight > The expected behaviour is the behaviour of Webkit (at very least the latest > chrome/safari releases) and Firefox 21. I just tested, and Firefox 21 behaves exactly like Firefox 22 on your steps to reproduce, as expected: our implementation of the linked spec bits about documentElement didn't change from 21 to 22. Can you double-check your testing in Firefox 21? And yes, the documentation is bogus...
Flags: needinfo?(a.beingessner)
Keywords: dev-doc-needed
Ah, yep. The w3 docs match the behaviour implemented. Then it's just a bug in mdn, and webkit is the mistaken one. I'm not very familiar with working with multiple versions of Firefox, my reference to 21 was simply the behaviour I remember experiencing. Is there a good way to regress my FF22 to 21, or otherwise get a parallel install to check? It may be worth noting that this was behaviour I was leveraging in an iframe to determine the minimum necessary height of the iframe to contain the document. So maybe it was only happening in iframes? Regardless, I don't think it's a big issue, since again, 22 has the correct behaviour. I can also just get the value I really wanted by getting the computed style.
Flags: needinfo?(a.beingessner)
Summary: documentElement.scrollHeight/clientHeight behaviour regression → documentElement.scrollHeight/clientHeight documentation incorrect
I've updated the title of the issue accordingly, thanks for your time.
On Mac (which I'm assuming you are given comment 0), you can just download Firefox 21 from ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/21.0/mac/en-US/Firefox%2021.0.dmg and save the app bundle on your desktop, and then run it directly from the app bundle using a different profile like so in Terminal: ~/Desktop/Firefox.app/Contents/MacOS/firefox-bin -profile /tmp/temp-profile
Assignee: nobody → bruant.d
Product: Core → Developer Documentation
Version: 22 Branch → unspecified
document.getElementsById("messages").scrollHeight on display: none elements returns zero, too. Bug?
Assignee: bruant.d → nobody
Priority: -- → P5
MDN Web Docs' bug reporting has now moved to GitHub. From now on, please file content bugs at https://github.com/mdn/sprints/issues/ and platform bugs at https://github.com/mdn/kuma/issues/.
Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.