offsetHeight is reported wrongly




DOM: Core & HTML
17 years ago
3 years ago


(Reporter: Chris Brien, Assigned: jst)




Firefox Tracking Flags

(Not tracked)



(1 attachment, 1 obsolete attachment)



17 years ago
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
BuildID:    2001021520

The property document.body.offsetHeight should return the height of the html 
rendering area. Instead, it returns the height of the content.
document.body.offsetWidth works properly.

Reproducible: Always

Steps to Reproduce:
Put a script into a page which includes something like this:

alert("The viewable area is " + document.body.offsetWidth + " pixels wide and " 
+ document.body.offsetHeight + " pixels high.");

Actual Results:  offsetWidth is reported correctly, whereas offsetHeight is the 
height of the actual content.

Expected Results:  Both offsetHeight and offsetWidth should report the size of 
the HTML rendering area.
Actually, doesn't offsetHeight just return the height of the DOM object
representing the body?  If so, that's not the height of the rendering area at
all, it _is_ the height of the content.

Does IE do it differently (giving you the height of the viewport)?

Comment 2

17 years ago
I would think that offsetHeight would show the height of the content (which may
be more or less than the viewport size). If you want the viewport size you could
use window.innerHeight in Netscape 4.x and Mozilla.

Comment 3

17 years ago

Comment 4

17 years ago
Created attachment 25462 [details]
testcase to show the offsetWidth, offsetHeight, innerWidth, and innerHeight

Comment 5

17 years ago
The values for document.body.offsetHeight is different than window.innerHeight
in the attached testcase. This is also true for document.body.offsetWidth
compared to window.innerWidth, so I'd say the original report is incorrect:
body.offsetWidth does not return the size of the viewport.

I'd say this is not a bug. If anything, I'd say IE's results are incorrect (and
IE doesn't support innerHeight and innerWidth).

Comment 6

17 years ago
It's hard to say that IE's .offsetXXX properties are incorrect since there's no
spec for those properties. What IE does is what's correct, unfortunately. The
semantics of these properties never cease to amaze me.

I don't know what to do here yet, but whatever is done it won't happen until
past mozilla0.9.1. Does existing sites break because of this?
Component: DOM Level 1 → DOM Level 0
Ever confirmed: true
OS: Windows NT → All
Priority: -- → P3
Hardware: PC → All
Target Milestone: --- → mozilla1.0
Keywords: qawanted
QA Contact: janc → desale

Comment 7

17 years ago
It's strange that the values for height and width seem to be different things. 
offsetWidth doesn't report the width of the content, but the width of the 
viewport, so I'd expect offsetHeigth to do the same.
This inconsistency makes it impossible to center things on screen, which is 
what I was trying to do when I noticed this bug.
Well, if I recall correctly, what mozilla reports for the offsetHeight and
offsetWidth are just the height and width CSS2 properties of the corresponding
box (so in this case, the height and width of the <body> box).  And if you put a
border around <body>, you'll see that the width of <body> is the width of the
viewport unless specified otherwise, while the height is the height of the
content unless specified otherwise.

If you want to center things, you should probably "specify otherwise" for the
body tag... something like:

body { position: absolute; left: 0; right: 0; top: 0; bottom: 0; margin: 0;
padding: 0 }
Keywords: dom0

Comment 9

16 years ago
Chris Brien, could you please re-test this now that offset* properties were
modifed to match IE's behavior? Thanks in advance!

Comment 10

16 years ago
Bugs targeted at mozilla1.0 without the mozilla1.0 keyword moved to mozilla1.0.1 
(you can query for this string to delete spam or retrieve the list of bugs I've 
Target Milestone: mozilla1.0 → mozilla1.0.1

Comment 11

16 years ago
Created attachment 61583 [details]
This test case uses the documentElement as well

Notice how this test case shows that IE6 and Mozilla are both giving the same
results. (Except that IE does not support innerWidth/Height)
Attachment #25462 - Attachment is obsolete: true
Marking worksforme, since this is working identically in IE6 and Mozilla....
Last Resolved: 16 years ago
Resolution: --- → WORKSFORME

Comment 13

16 years ago
I was also going to add a comment but it got lost in cyberspace.... here we go again

This bug is invalid.

The offset* for body should give the size of the body element. Notice that
Mozilla and IE6 in CSS1Compat mode behaves exactly the same. The reason why IE
(before IE6) gave the window inner size (for body.offset*) was that IE treated
the body element as the document canvas.

Comment 14

13 years ago
*** Bug 258531 has been marked as a duplicate of this bug. ***
Keywords: qawanted
You need to log in before you can comment on or make changes to this bug.