From: Larry Martell on 23 Jul 2010 08:31 Hello all- I have a php script that generates a web page with a bunch of scrollable frames, and then asynchronously refreshes the page. If the user has scrolled down in any of the frames, when the refresh occurs it has scrolled back to the top of all the frames. Is there a way I can retain the scroll position so after the refresh the frames are shown at the same location as before the refresh? I have googled and googled for this, but everything I find is ASP or C# or Java. My stuff is straight php/html. How can I do this with that? TIA! -larry
From: =?UTF-8?Q?Hans_=C3=85hlin?= on 23 Jul 2010 10:48 I't was a long time ago when i programed in js but the first thin that pops up in my mind is that there is a function where you can read and set the values of the scrollbars. I found this when I googled it: http://www.eggheadcafe.com/community/aspnet/3/10002280/scroll-positions.aspx <http://www.eggheadcafe.com/community/aspnet/3/10002280/scroll-positions.aspx> http://www.daniweb.com/forums/thread60189.html ********************************************** Hans à hlin Tel: +46761488019 icq: 275232967 http://www.kronan-net.com/ irc://irc.freenode.net:6667 - TheCoin ********************************************** 2010/7/23 Larry Martell <larry.martell(a)gmail.com> > Hello all- > > I have a php script that generates a web page with a bunch of > scrollable frames, and then asynchronously refreshes the page. If the > user has scrolled down in any of the frames, when the refresh occurs > it has scrolled back to the top of all the frames. Is there a way I > can retain the scroll position so after the refresh the frames are > shown at the same location as before the refresh? I have googled and > googled for this, but everything I find is ASP or C# or Java. My stuff > is straight php/html. How can I do this with that? > > TIA! > -larry > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
From: tedd on 23 Jul 2010 12:31 At 6:31 AM -0600 7/23/10, Larry Martell wrote: >Hello all- > >I have a php script that generates a web page with a bunch of >scrollable frames, and then asynchronously refreshes the page. If the >user has scrolled down in any of the frames, when the refresh occurs >it has scrolled back to the top of all the frames. Is there a way I >can retain the scroll position so after the refresh the frames are >shown at the same location as before the refresh? I have googled and >googled for this, but everything I find is ASP or C# or Java. My stuff >is straight php/html. How can I do this with that? > >TIA! >-larry I forgot, this *is* Friday (as Daniel reminded me) -- so everyone here's the code I provided to Larry. -larry: This is a problem that can be solved via javascript. The process is that you create a cookie containing the scroll position value before the operation (whatever that may be) and then you restore the page back to where it was after the operation. The following is the javascript code I wrote several years ago -- it works for me. Cheers, tedd --- javascript --- addLoadListener(init); function init() { window.onscroll = function() { var scrollpos = getScrollingPosition(); document.title = 'left=' + scrollpos[0] + ' top=' + scrollpos[1]; //-- create a cookie named scrollPosition and put the vertical scroll amount in the value var cookieName = "scrollPosition"; var cookieValue = scrollpos[1]; var theCookie = cookieName + "=" + cookieValue; document.cookie = theCookie; }; return true; } function getScrollingPosition() { var position = [0, 0]; if (typeof window.pageYOffset != 'undefined') { position = [ window.pageXOffset, window.pageYOffset ]; } else if (typeof document.documentElement.scrollTop != 'undefined' && (document.documentElement.scrollTop > 0 || document.documentElement.scrollLeft > 0)) { position = [ document.documentElement.scrollLeft, document.documentElement.scrollTop ]; } else if (typeof document.body.scrollTop != 'undefined') { position = [ document.body.scrollLeft, document.body.scrollTop ]; } return position; } function addLoadListener(fn) { if (typeof window.addEventListener != 'undefined') { window.addEventListener('load', fn, false); } else if (typeof document.addEventListener != 'undefined') { document.addEventListener('load', fn, false); } else if (typeof window.attachEvent != 'undefined') { window.attachEvent('onload', fn); } else { var oldfn = window.onload; if (typeof window.onload != 'function') { window.onload = fn; } else { window.onload = function() { oldfn(); fn(); }; } } } function getCookie(searchName) { var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { var cookieCrumbs = cookies[i].split("="); var cookieName = cookieCrumbs[0]; var cookieValue = cookieCrumbs[1]; if (cookieName == searchName) { return cookieValue; } } return false; } function myscroll() { // on load the cookie scrollPosition's value is read and scrolled to var scrollValue = getCookie("scrollPosition"); window.scrollTo(0, scrollValue); } -- ------- http://sperling.com http://ancientstones.com http://earthstones.com
|
Pages: 1 Prev: SOAP ERROR - Encoding Next: Tutte le soluzioni per recuperare un RAID |