Maintain a Div's Scroll Position After refresh

C

crazychrisy54

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
 
C

crazychrisy54

My overflow div is also encapsulated within another stard div but I
don't think that would be a problem
Thanks for your time
 
C

crazychrisy54

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
 
T

Thomas 'PointedEars' Lahn

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.
 
C

crazychrisy54

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.


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top