Is there a way to detect a page height/length in js?
My main point is having the back top link appear only when needed.
Thanks for your time.
| SitePoint Sponsor |
Is there a way to detect a page height/length in js?
My main point is having the back top link appear only when needed.
Thanks for your time.
You can check for the window's height, but I've never heard of page height, unless you have a pixel-perfect design, in which case your page's height is probably listed in your HTML or CSS code. However, if you do find anything, please post the solution -- I'm sure we'd all be glad to hear what it is!
--Vinnie
You can probably use the document.body's offsetHeight, scrollHeight or clientHeight properties, together with the document.height property.
The problem is though, that the page height isn't known until the entire page has actually been rendered. If you're lucky, it's updated dynamically as the page is being rendered. In that case, you could stuff some javascript near the end of the page similar to:
If that doesn't work (and I doubt it does), you might just have to put in a blank image by default, and replace it with a "back-to-top" image once the page has loaded, and (obviously) only if the page is higher than the client's scroll area.Code:if (document.height > document.body.scrollHeight) { document.write('<a href="#top"><img src="top.gif"></a>'); }
Just my $0.02![]()
"A poor programmer is he who blames his tools."
http://analyser.oli.tudelft.nl/
Bookmarks