Click to See Complete Forum and Search --> : how to reach page bottom on body load
vinitjain
September 12th, 2002, 02:41 AM
HI,
i have this chat which refreshes every two seconds. NOw the problem is, users have to scroll down bottom to view last posted msg. Any javascript code by which i can automatically reach the page bottom whenever the page is loaded ??
Its lil urgent !
Thnx
Vinit
Zvona
September 12th, 2002, 01:07 PM
Use : myDocument.html#bottom as an URI of the refresh redirection.
and apply :
<body>
.
.
.
.
.
<a name="bottom"></a>
</body>
now, everytime page reloads, it's scrolled to bottom.
With JS :
<body onload="scrollTo(0,10000);">
this scrolls page down to 10000 pixels. If you have less than 10000 px as an height, document is still scrolled to bottom.
Waldo2k2
September 12th, 2002, 07:05 PM
actually there's a better way. You don't need the link, and you can use JavaScript. The problem with Zvona's method is that just scrolling down an arbitrarily large number (ie:10,000px) is not clean or efficient code. And it is highly unlikely but possible that at some point it may go beyond 10,000px. So...do this
var bottomOut=parseInt(document.body.clientHeight);
...
<body onload="javascript:scrollTo(0,bottomOut);">
that should work. If not, check to see if it will work without using the parseInt function on document.body.clientHeight. Good Luck.
vinitjain
September 13th, 2002, 12:39 AM
Thanx a TON to both Zvona AND Waldo2k2 for your help. Although both ways worked fine but i am opting Waldo2k2's method bcos that seemed more reliable for whatever be the length of page it will work.
Thanx to you both :)
Vinit
Zvona
September 13th, 2002, 02:55 AM
Hmm..that's true. I've always used that 10000px in my rare test cases. Useful idea.
Just remember that there are still users with scripting disabled.
websmith99
September 19th, 2002, 06:34 PM
Just a note on the clientHeight property.
var bottomOut=parseInt(document.body.clientHeight);
will only work on IE4+
For Netscape 4 and Netscape 6, use:
var bottomOut= innerHeight;
So do browser detection and define bottomOut appropriately.
Also, <body onload="scrollTo(0,10000);"> will not work with
scripting disabled either.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.