[PHP] Retaining scroll position after asynchronous refresh

2010-07-23 Thread Larry Martell
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



Re: [PHP] Retaining scroll position after asynchronous refresh

2010-07-23 Thread Hans Åhlin
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.mart...@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




Re: [PHP] Retaining scroll position after asynchronous refresh NOT PHP

2010-07-23 Thread tedd

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


-larry:

This not really a PHP problem, but rather a javascript problem. After 
all, the problem surfaces client-side, right?


So, to not offend this list with a non-PHP solution, I am sending you 
the code privately.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Retaining scroll position after asynchronous refresh NOT PHP

2010-07-23 Thread Daniel P. Brown
On Fri, Jul 23, 2010 at 12:09, tedd tedd.sperl...@gmail.com wrote:

 This not really a PHP problem, but rather a javascript problem. After all,
 the problem surfaces client-side, right?

 So, to not offend this list with a non-PHP solution, I am sending you the
 code privately.

Well, it *is* Friday

P.S. - Tedd, when you get a chance, call my cell phone really quick, please.

-- 
/Daniel P. Brown
UNADVERTISED DEDICATED SERVER SPECIALS
SAME-DAY SETUP
Just ask me what we're offering today!
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Retaining scroll position after asynchronous refresh

2010-07-23 Thread tedd

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Retaining scroll position after asynchronous refresh NOT PHP

2010-07-23 Thread Nathan Nobbe
On Fri, Jul 23, 2010 at 10:09 AM, tedd tedd.sperl...@gmail.com wrote:

 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?


how are you doing the refresh?  a location header or http meta tag?  both of
those are gross imo - try ajax and i bet your problem goes away.

-nathan