The Little Guy Posted April 15, 2009 Share Posted April 15, 2009 OK, I want to maintain scroll position, I found this: function getScrollXY() { var x = 0, y = 0; if( typeof( window.pageYOffset ) == 'number' ) { // Netscape x = window.pageXOffset; y = window.pageYOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { // DOM x = document.body.scrollLeft; y = document.body.scrollTop; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { // IE6 standards compliant mode x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; } return [x, y]; } function setScrollXY(x, y) { window.scrollTo(x, y); } But, the problem is that I have no idea how to use it... I found it here: http://abeautifulsite.net/notebook/10 Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 15, 2009 Share Posted April 15, 2009 It's as simple as it looks, however it may need to be updated in order to still be cross browser compatible. You use the top function to get the position of the browsers scrollbar and store that value somewhere. I assume that for most sites, it will be [0,n] since not many sites scroll horizontally. From there, say you stored that value in a cookie, if the user came back to that page, you could read that value and apply the second function to scroll the browser window back to that spot. pseudocode: (ex: user is reading a long post) user enters page has user been here before [yes] - is value stored? [y] - scroll to [n] - do nothing [no] - do nothin 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.