View Full Version : positioning in iframe page

06-30-2004, 11:44 PM

I am building a small messenger and I am using three iframes. One for displaying the messages and one for entering the messages and one hidden iframe for polling.

I want the lines in the display window to scroll up and than position at the bottom (so the last message is at the last line and visible)

How do I do that? (I dont want to use the <A name=... Anchor for jumping to the bottom after reloading the display window.)

06-30-2004, 11:52 PM
You can try using the scrollTo() method:

The next question may be: what values do I pass to scrollTo() (like where's the bottom going to be necessarily?)

I'm not too sure how it would work, but my guess might be to find out how big the body area is, and then scroll to that Y-value. Just my guess, I've never tried it..

Mess around with it and see if you can get it to go. Perhaps in the meanwhile someone with the knowledge can advise you better.

Good luck,

07-01-2004, 12:02 AM
You could use window.innerHeight / document.body.offsetHeight in conjuction with window.scrollTo(), e.g.:

if(document.all) window.scrollTo(0, document.body.offsetHeight);
else window.scrollTo(0, window.innerHeight);

Note: You can use this only if the body-tag was already loaded so it would make sense to start the execution of the function with the onload-event.

07-01-2004, 08:15 AM
The option Sad69 offered suited best for me. I've build this small function which runs at onload.

function toBottom() {
self.scrollTo(0, 9999999)

It works fine with ie6 do some of you expect problems with other browsers?

07-01-2004, 10:16 AM
I think this is better:

function toBottom() {
self.scrollTo(0, document.body.scrollHeight);

07-02-2004, 01:08 PM
Thank you I also like this better. :thumbsup: