jakeoh Posted October 23, 2007 Share Posted October 23, 2007 I added a shoutbox to my site; messages are displayed in a <div> section and refreshed every couple of seconds. Since there can be lots of messages in this section, scrollbars are used. The problem is, when someone wants to scroll through the messages, he is always brought back to the top by the funcrion that refreshes the shoutbox. Here's the code in the .js file: function showData() { htmlRequest = ajaxFunction(); if (htmlRequest==null){ // If it cannot create a new Xmlhttp object. alert ("Browser does not support HTTP Request"); return; } htmlRequest.onreadystatechange = function(){ if(htmlRequest.readyState == 4){ document.getElementById("shoutarea").innerHTML = htmlRequest.responseText; } } htmlRequest.open("GET", "outputinfo.php", true); htmlRequest.send(null); } showData(); setInterval("showData()",5000); And here's the code in the php file: <? include("Include/shoutbox_connect.php"); open_connection(); $shout_query = "SELECT * FROM shoutbox ORDER BY `date` DESC LIMIT 10"; $shout_result = mysql_query($shout_query); $count = 0; echo '<div style="border:1px #000000 solid; width:200; height:278px; overflow:auto;">'; while($shout_row = mysql_fetch_array($shout_result)) { $shouter_name = $shout_row['username']; $shout_content = $shout_row['content']; $shout_content = stripslashes($shout_content); $shout_date = $shout_row['date']; // $dday = substr($shout_date, 8, 2); $dday = strftime('%d/%m/%y', strtotime($shout_date)); $dtime = strftime('%H:%M:%S', strtotime($shout_date)); $dmonth = substr($shout_date, 5, 2); $dyear = substr($shout_date, 0, 4); $dhour = substr($shoutdate, 11,2); $dminute = substr($shoutdate, 14,2); if(($count % 2) != 0) { echo "<p class='shoutboxCssOdd'><b>$shouter_name</b> said, on $dday à $dtime: <br> $shout_content </p>"; } else { echo "<p class='shoutboxCssEven'><b>$shouter_name</b> said, on $dday à $dtime: <br> $shout_content </p>"; } $count++; } ?> </div> Anyone has a hint on how I can prevent this? Quote Link to comment Share on other sites More sharing options...
jakeoh Posted October 26, 2007 Author Share Posted October 26, 2007 Anyone has an idea? Quote Link to comment Share on other sites More sharing options...
jakeoh Posted November 6, 2007 Author Share Posted November 6, 2007 I tried a couple of things but I'm way over my head. I guess I should use the onscroll function to monitor the use of the scrollbar... but then what do I do? How can I do the following: onscroll=stop the setInterval of the showdata() function, and then somehow set it again after a certain time or when the scroll is not used anymore. Help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.