1

I am using an Iframe which reloads itself every 5 seconds. It makes use of javascript to automaticly scroll to the bottom because it has too much content to display in one go, but sometimes after a refresh the scroll bar doesn't go down all the way. Leaving me scrolling it down myself.

I really don't know what it is. Maybe one of you has a better peice of Javascript suited for this.

Javascript:

<script>
var objDiv = document.getElementById("chat");
objDiv.scrollTop = objDiv.scrollHeight;
</script>

The HTML div:

<div id="chat" class="scroll">
*Content going on for 150 lines...*
</div>

Thanks in advance.

  • try to put it inside window.onload, like this: `window.onload = function(){//code here}`.. – Bla... Jul 21 '14 at 14:49
  • [This `scrollTop` assignment should work](http://jsfiddle.net/D8MTy/), error is probably in some surrounding code. You should add that to the question, as it is relevant – blgt Jul 21 '14 at 14:51
  • try to put it inside window.onload, like this: window.onload = function(){//code here}.. – user3003216 THIS WORKED! please put it into an answer so I can accept it. – user3813511 Jul 21 '14 at 16:40

1 Answers1

0

You could conceivably create a placeholder div at the bottom of your page, and use this answer to scroll to the bottom of it. This would ensure that you always scroll to that div, rather than what the query perceives as the bottom of the page.

Community
  • 1
  • 1
Wolfish
  • 960
  • 2
  • 8
  • 34