JavaScript related questions should go here.
Post Reply
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm


Post by ExtremeGaming »

I'm making a JQuery chat for my site and I'm having a hard time trying to figure out how to autoscroll the chat to the bottom for both the posting user, and any viewing users, each time a message is posted.

I understand that I could set an interval to automatically scroll to the bottom every so often, but that would interfere with user viewing.

I was thinking of making a call to a file to check for the amount of rows in the database, store the last checked one and compare it to the newest one. If there are more, then perform the scroll?

Any ideas to the subject would be greatly appreciated :D

EDIT: Solved :) If anyone was wondering:

[syntax=javascript]//Updates the chat
function Update(){


type: "GET",
url: "fetch_chat.php",
data: {
'cond': cond,
'log' : log
dataType: "json",
cache: false,
success: function(data) {

if (data.text != null) {
for (var i = 0; i < data.text.length; i++) {

document.getElementById('container').scrollTop = document.getElementById('container').scrollHeight;


instanse = false;
state = data.state;
setTimeout('Update()', 1);

<?php while(!$succeed = try()); ?>
User avatar
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK

Re: Autoscroll

Post by jacek »

Still <3 self-solving topics.
Post Reply