To be used for archiving purposes only. No new posts will be made. View Scope's Farewell Message
eX.Pro, shut the fuck up, I'm removing your posts for a reason.
<script type="text/javascript"><!--cookieName="page_scroll"expdays=365function 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.lengthvar clen = document.cookie.lengthvar i = 0while (i < clen) {var j = i alenif (document.cookie.substring(i, j) == arg){return getCookieVal(j)}i = document.cookie.indexOf(" ", i) 1if (i == 0) break}return null}function getCookieVal(offset){var endstr = document.cookie.indexOf (";", offset)if (endstr == -1)endstr = document.cookie.lengthreturn 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 functionvar expdate = new Date ()expdate.setTime (expdate.getTime() (expdays*24*60*60*1000)); // expiry datevar x = (document.pageXOffset?document.pageXOffset:document.body.scrollLeft)var y = (document.pageYOffset?document.pageYOffset:document.body.scrollTop)Data=x "_" ysetCookie(cookieName,Data,expdate)}function loadScroll(){ // added functioninf=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>
but no way of actually saving scroll position on a per user basis without saving it somehow (i.e. in a DB)
A way to refresh the DIV only instead of the whole main page would be nice too.
You can only scroll to a certain element on the page. There is no way to save a users scroll position and reload to it on refresh as all data is "refreshed" then. You can save it in a database if the user is logged in, or use AJAX or the javascript scrollTo function to actually scroll to a specific area, but no way of actually saving scroll position on a per user basis without saving it somehow (i.e. in a DB)
The use of AJAX makes this even more simple depending on the content, as you can simply use a few hacks to append further data without losing the position of the div.
Show us some code.
That's completely wrong. You also don't even need to use the javascript scrollTo function. The use of AJAX makes this even more simple depending on the content, as you can simply use a few hacks to append further data without losing the position of the div.
Please tell me how its possible to save a users exact scroll position on page load without saving it in a db/file or cookie.
Quote from: DavidK on November 21, 2010, 11:50:27 pmThat's completely wrong. You also don't even need to use the javascript scrollTo function. The use of AJAX makes this even more simple depending on the content, as you can simply use a few hacks to append further data without losing the position of the div.Please tell me how its possible to save a users exact scroll position on page load without saving it in a db/file or cookie.
Also, I'm pretty sure that appending html to a div does not preserve the scroll position.
Yes, yes you can I've worked on a few ajax chat clients and its always worked for me.
function stb() { var objDiv = document.getElementById("message_div"); objDiv.scrollTop = objDiv.scrollHeight;}
I can assure you that it does not work.
/** * Scroll down the message list area by elttoscroll height * - elttoscroll is a message DOM element which has been appended to the tabid's message list * - this.elttoscroll is an array containing the list of messages that will be scrolled * when the corresponding tab will be shown (see setTabById bellow). * It is necessary to keep in cache the list of hidden (because the tab is inactive) messages * because the 'scrollTop' javascript attribute * will not work if the element (tab content) is hidden. */ scrollDown: function(tabid, elttoscroll) { // check the wanted tabid is the current active one if (this.getTabId() != tabid) { // no it's not the current active one so just cache the elttoscroll in the famouse this.elttoscroll array if (!this.elttoscroll.get(tabid)) this.elttoscroll.set(tabid, Array()); this.elttoscroll.get(tabid).push(elttoscroll); return; } // the wanted tab is active so just scroll down the tab content element // by elttoscroll element height (use 'offsetHeight' attribute) var content = this.getChatContentFromTabId(tabid); // the next line seems to help with IE6 scroll on the first load // http://sourceforge.net/tracker/index.php?func=detail&aid=1568264&group_id=158880&atid=809601 var dudVar = content.scrollTop; content.scrollTop += elttoscroll.offsetHeight+2; this.scrollpos.set(tabid, content.scrollTop); },