Closed Thread Icon

Topic awaiting preservation: SHORT DEADLINE : How do you get the total page/document height? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8698" title="Pages that link to Topic awaiting preservation: SHORT DEADLINE : How do you get the total page/document height? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: SHORT DEADLINE : How do you get the total page/document height? <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 06-07-2003 02:05

Hi again,

Basically I need a way to get the height of a full document from start to end, not just the size of the window.

I have found a few methods, but they are all browser specific:

document.body.scrollHeight - this works in pc ie and mozilla/netscape (only tried v7)

document.documenElement.offsetHeight - this works for mac ie 5.1 (maybe previous versions too)

document.body.offsetHeight - this is supposed to work for opera 7, but seems unreliable

Now I need to be able to get the height of the entire document using the onLoad command (whether it be in the body tag or in a js function in the head)

I would like to be able to get the heights for the following browsers:

opera 6
opera 7
pc ie 5+
mac ie 5+
mozilla/netscape 6+

Any ideas you wonderfully knowledgeable people?

[This message has been edited by smonkey (edited 06-07-2003).]

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-07-2003 08:42

This is how I do it:

d = document? document : 0
db = d.body? d.body :0
de = d.documentElement? d.documentElement : 0

winHeight = (de && de.clientHeight)? de.clientHeight : (db && db.clientHeight)? db.clientHeight : (window.innerHeight)? window.innerHeight : 0

It's best to detect which methods to use by trying to read the values rather than trying to guess that browser and assigning whatever value you think will work.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 06-07-2003 17:21

Dracusis, from looking at that script with my naive little eyes, I get the impression it only will give me the height of the inner part of the window and not the overall height of the document itself including the parts that are still off screen - you get me?

I need something to measure the length/height of the entire document

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-08-2003 05:55

Oh... that...

Er, just do it the same way with the properties you have listed above. But you'll need to wait for the document to load before a property like that will give you the answer you want.. me thinks.

Just remember that document.body becomes document.documentElement for IE when it's in standard compliant mode. Both document.body and document.documentElement both exist in either rendering mode but one set of values will always be empty, so be sure to test for the absolute value and not just the object it resides in.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-08-2003 06:06

I don't think that'll work, because the body of the document is always the height of the document window, with a scrollbar (the main scrollbar).

Rather, you might try:

- wrapping the entire page in a DIV tag, and then getting the offsetHeight property of that DIV tag
- finding the last child in the body (document.body.childNodes[document.body.childNodes.length-1]), and getting its offsetTop + its offsetHeight

Note that document.documentElement doesn't refer to the body tag, it refers to the HTML tag. When it's defined.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 06-09-2003 00:09

cheers buddies, this is going well - the only browser I can't get to work is opera 6.

the methods i wrote in the first post all work and do return the full length of the loaded page, and not just the viewport. I have my script working in Mozilla pc and mac , IE 5+ pc and mac, and Opera 7 pc and mac. But I really need a method for opera 6 now. From prowling around I have found the pixelHeight thing for opera 6 but this doesn't seem to work (

in fact i have found a whole list of things that opera 6 apparently supports but haven't got any of them to work, any ideas?

pageYOffset
offsetY
offsetTop
availHeight
pixelTop
pixelHeight
innerHeight

it must be possible.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-09-2003 00:21

Opera 6 is generally hopeless when it comes to the DOM. There may be a way, but I haven't worked with that particular version of Opera, and it's unlikely that it's really worth figuring out. Instead, I encourage you to find an acceptable alternative to whatever feature you're implementing that people can use when their browsers don't support your script.

« BackwardsOnwards »

Show Forum Drop Down Menu