Maintain a Div's Scroll Position After refresh

  • Follow


Hi there

I have used some javascript very similar to other examples on the net
in order ro remember where my overflow div scroll position is after a
refresh.

This code works fine with firefox but with IE it flickers too much
because the scroll first goes to the top left part of the image and
then scrolls back down to the users previous scroll position. Does
anyone have any suggestions how to fix this problem or am I stuck!?

Any help would be much appreciated

The code I used was adapted from Eric Pascarello's "remember a div
scroll position" and is as follows:

Javascript:

window.onload = function(){
	var strCook = document.cookie;
    if(strCook.indexOf("!~")!=0){
		var intStart = strCook.indexOf("!~");
 		var intEnd = strCook.indexOf("~!");
    	var strVerticalScrollValue = strCook.substring(intStart
+2,intEnd);
    	document.getElementById("pmDIV").scrollTop =
strVerticalScrollValue;
 	 }
 	 if(strCook.indexOf("!#")!=0){
		var intStart = strCook.indexOf("!#");
 		var intEnd = strCook.indexOf("#!");
    	var strHorizontalScrollValue = strCook.substring(intStart
+2,intEnd);
  		document.getElementById("pmDIV").scrollLeft =
strHorizontalScrollValue;
 	 }}

 function SetDivPosition(){
 	var intY = document.getElementById("pmDIV").scrollTop;
	var intX =
document.getElementById("pmDIV").scrollLeft;
	document.cookie = "yPos=!~" + intY + "~!";
	document.cookie = "xPos=!#" + intX + "#!";
}


HTML page:
<div id="pmDIV" onscroll="SetDivPosition()" style="overflow: auto;"
       //Includes a ever growing image
</div>

Thanks again for your time
Chris
0
Reply crazychrisy54 4/24/2008 3:55:45 PM

My overflow div is also encapsulated within another stard div but I
don't think that would be a problem
Thanks for your time
0
Reply crazychrisy54 4/25/2008 7:35:01 AM


Sorry to bring this issue up again but does anyone have ideas on
solving this problem or do you think it is a pure IE bug which can't
be fixed?

Thanks
Chris
0
Reply crazychrisy54 4/28/2008 7:59:36 AM

:(
0
Reply crazychrisy54 4/29/2008 2:39:47 PM

crazychrisy54@hotmail.com wrote:
> I have used some javascript very similar to other examples on the net in
> order ro remember where my overflow div scroll position is after a 
> refresh.
> 
> This code works fine with firefox

I don't think Firefox even needs that code.  At least for me, the scroll
position is restored automatically if I refresh (without overriding the
cache).  That includes scrollable block elements.

> but with IE it flickers too much because the scroll first goes to the top
> left part of the image and then scrolls back down to the users previous
> scroll position. Does anyone have any suggestions how to fix this problem
> or am I stuck!?

Probably you are stuck.  Client-side scripting cannot reasonably remedy all
the shortcomings of a user agent.  You should use the standards-compliant

  <body onload="...">

instead of the proprietary

  window.onload = ...

but the change is unlikely to help with your particular problem.


BTW, Usenet is _not_ a real-time communications medium, and you better
observe the communication standards that have been established in it if
you wish to receive a helpful answer.  See http://jibbering.com/faq/ pp.


-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann
0
Reply Thomas 4/29/2008 5:38:17 PM

On Apr 29, 6:38 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> crazychris...@hotmail.com wrote:
> > I have used some javascript very similar to other examples on the net in
> > order ro remember where my overflow div scroll position is after a
> > refresh.
>
> > This code works fine with firefox
>
> I don't think Firefox even needs that code.  At least for me, the scroll
> position is restored automatically if I refresh (without overriding the
> cache).  That includes scrollable block elements.
>
> > but with IE it flickers too much because the scroll first goes to the top
> > left part of the image and then scrolls back down to the users previous
> > scroll position. Does anyone have any suggestions how to fix this problem
> > or am I stuck!?
>
> Probably you are stuck.  Client-side scripting cannot reasonably remedy all
> the shortcomings of a user agent.  You should use the standards-compliant
>
>   <body onload="...">
>
> instead of the proprietary
>
>   window.onload = ...
>
> but the change is unlikely to help with your particular problem.
>
> BTW, Usenet is _not_ a real-time communications medium, and you better
> observe the communication standards that have been established in it if
> you wish to receive a helpful answer.  Seehttp://jibbering.com/faq/pp.
>
> --
>     realism:    HTML 4.01 Strict
>     evangelism: XHTML 1.0 Strict
>     madness:    XHTML 1.1 as application/xhtml+xml
>                                                     -- Bjoern Hoehrmann

Thanks Thomas, I've made that change but unfortunately to no prevail,
I think I definitely am stuck and will have to look for an alternative
to achieve the functionality I require.

In addition, I've read those communication standards and apologise for
my mistake, won't happen again.
Regards
Chris
0
Reply crazychrisy54 5/2/2008 7:55:42 AM

5 Replies
729 Views

(page loaded in 0.071 seconds)

Similiar Articles:






Reply: