Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

document.height

4 views
Skip to first unread message

MartijnW

unread,
May 18, 2005, 5:52:43 AM5/18/05
to
See:
http://www.mozilla.org/docs/dom/domref/dom_doc_ref20.html
I tried setting the document.height, but I get an error ("setting a
property that only has a getter" or something like that.
So, I think the documentation is false.

Also what is meant by the document height?
The height of the html element?

I'm searching for a to find the actual height of a document (not the
html element, which can have a smaller height than the document).
Is there a way with regular dom methods?

Regards,
Martijn

MartijnW

unread,
May 18, 2005, 7:17:30 AM5/18/05
to
This reminds me of https://bugzilla.mozilla.org/show_bug.cgi?id=260498 -
nsGenericHTMLElement::offsetWidth returns different values for the root
element
In older builds, document.documentElement.offsetHeight was the height of
the canvas, but not anymore now (which is correct, afaik).
But now there doesn't seem to be a way to get the actual height of the
canvas.

Maybe something like this should work?
var height =
document.defaultView.getComputedStyle(document,'-moz-canvas').getPropertyValue("height");
This isn't allowed since getComputedStyle only accepts elements, not
document.

Martin Honnen

unread,
May 18, 2005, 7:57:35 AM5/18/05
to

MartijnW wrote:

> See:
> http://www.mozilla.org/docs/dom/domref/dom_doc_ref20.html
> I tried setting the document.height, but I get an error ("setting a
> property that only has a getter" or something like that.
> So, I think the documentation is false.

With Netscape 4 you could set document.height (and you had to if you
wanted your dynamically created layers to show up) but I don't think it
was ever possible to set document.height in Mozilla.

> Also what is meant by the document height?

I think it is the height of the canvas.


--

Martin Honnen
http://JavaScript.FAQTs.com/

MartijnW

unread,
May 18, 2005, 9:05:59 AM5/18/05
to
Martin Honnen wrote:
> With Netscape 4 you could set document.height (and you had to if you
> wanted your dynamically created layers to show up) but I don't think it
> was ever possible to set document.height in Mozilla.

So that documentation needs to be fixed.

>> Also what is meant by the document height?
>
>
> I think it is the height of the canvas.

I don't think so, consider this testcase:

<html style="height:100px;"><head></head>
<body style="height:50px;">
<button onclick="alert(document.height)">doe</button>
<div
style="position:absolute;top:50px;height:2000px;width:50px;border:2px
solid red;"></div>
</body>
</html>

This alerts 50 for me in current trunk build.

Regards,
Martijn

Martin Honnen

unread,
May 18, 2005, 9:06:56 AM5/18/05
to

MartijnW wrote:

> Martin Honnen wrote:
>
>
>>> Also what is meant by the document height?
>>
>>
>>
>> I think it is the height of the canvas.
>
>
> I don't think so, consider this testcase:
>
> <html style="height:100px;"><head></head>
> <body style="height:50px;">
> <button onclick="alert(document.height)">doe</button>
> <div
> style="position:absolute;top:50px;height:2000px;width:50px;border:2px
> solid red;"></div>
> </body>
> </html>
>
> This alerts 50 for me in current trunk build.

It seems
document.documentElement.scrollHeight
gives the height of the canvas but I think document.height should also
give that, looks like a bug to me.

MartijnW

unread,
May 18, 2005, 9:38:41 AM5/18/05
to
Martin Honnen wrote:
>
> It seems
> document.documentElement.scrollHeight
> gives the height of the canvas but I think document.height should also
> give that, looks like a bug to me.
>

Wait a minute, I mean with the canvas, what is said here:
http://www.w3.org/TR/CSS21/intro.html#q4
It seems like you interpret the canvas as the root element.
document.documentElement.scrollHeight returns 100 to me, but I want the
'real' document height (2054 as it seems).


Regards,
Martijn

Boris Zbarsky

unread,
May 18, 2005, 11:26:58 AM5/18/05
to
MartijnW wrote:
> Wait a minute, I mean with the canvas, what is said here:
> http://www.w3.org/TR/CSS21/intro.html#q4

Which is defined to have infinite extent....

-Boris

MartijnW

unread,
May 18, 2005, 12:15:52 PM5/18/05
to
Ok, ok, you're right. I meant the part of the canvas where the rendering
takes place.
So that's what I want, the height of the rendering part of the canvas.

Regards,
Martijn

Boris Zbarsky

unread,
May 18, 2005, 12:45:23 PM5/18/05
to
MartijnW wrote:
> Ok, ok, you're right. I meant the part of the canvas where the rendering
> takes place.
> So that's what I want, the height of the rendering part of the canvas.

And if this is smaller than the viewport then you don't want it increased to the
viewport height, right?

-Boris

Martijn Martijn

unread,
May 18, 2005, 1:25:35 PM5/18/05
to
Ehm well, I haven't thought about that, but no, I don't think I would
want that.
I can always get the viewport height with window.innerHeight, I think.

MartijnW

unread,
May 31, 2005, 7:03:39 AM5/31/05
to
MartijnW wrote:
> I'm searching for a to find the actual height of a document (not the
> html element, which can have a smaller height than the document).
> Is there a way with regular dom methods?
I think I finally found a way to get the document height:
window.innerHeight+window.scrollMaxY;
is the answer, I think.

Try it with this example (document.documentElement.offsetHeight won't
give the value I/you want):
<html><head></head>
<body>
<div
style="position:absolute;height:2000px;top:0;background-color:green;">test</div>
<button onclick="alert(window.innerHeight+window.scrollMaxY)">doe</button>
</body>
</html>

Regards,
Martijn

0 new messages