shebbycs Posted December 9, 2011 Share Posted December 9, 2011 Chatlog.php <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?> <script> setTimeout("window.location.replace('chatlog.php')",2000); var objDiv = document.body; objDiv.scrollTop = objDiv.scrollHeight; </script> Javascript for to reload the page in same scroll position <script type="text/javascript"> <!-- cookieName="page_scroll" expdays=365 // An adaptation of Dorcht's cookie functions. function setCookie(name, value, expires, path, domain, secure){ if (!expires){expires = new Date()} document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + ((path == null) ? "" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) + ((secure == null) ? "" : "; secure") } function getCookie(name) { var arg = name + "=" var alen = arg.length var clen = document.cookie.length var i = 0 while (i < clen) { var j = i + alen if (document.cookie.substring(i, j) == arg){ return getCookieVal(j) } i = document.cookie.indexOf(" ", i) + 1 if (i == 0) break } return null } function getCookieVal(offset){ var endstr = document.cookie.indexOf (";", offset) if (endstr == -1) endstr = document.cookie.length return unescape(document.cookie.substring(offset, endstr)) } function deleteCookie(name,path,domain){ document.cookie = name + "=" + ((path == null) ? "" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) + "; expires=Thu, 01-Jan-00 00:00:01 GMT" } function saveScroll(){ // added function var expdate = new Date () expdate.setTime (expdate.getTime() + (expdays*24*60*60*1000)); // expiry date var x = (document.pageXOffset?document.pageXOffset:document.body.scrollLeft) var y = (document.pageYOffset?document.pageYOffset:document.body.scrollTop) Data=x + "_" + y setCookie(cookieName,Data,expdate) } function loadScroll(){ // added function inf=getCookie(cookieName) if(!inf){return} var ar = inf.split("_") if(ar.length == 2){ window.scrollTo(parseInt(ar[0]), parseInt(ar[1])) } } // add onload="loadScroll()" onunload="saveScroll()" to the opening BODY tag // --> </script> Any one can combinie my script with this script? Quote Link to comment https://forums.phpfreaks.com/topic/252844-page-reloads-it-will-be-at-the-same-scroll-position/ Share on other sites More sharing options...
shebbycs Posted December 9, 2011 Author Share Posted December 9, 2011 im had solved the problem thanks you Quote Link to comment https://forums.phpfreaks.com/topic/252844-page-reloads-it-will-be-at-the-same-scroll-position/#findComment-1296336 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.