Auto scroll to correct position?

M

Martin

I have a web page (IE only; intranet only) that is both wider and
longer than the browser window. I've noticed that if the user has
scrolled the page DOWN and then refreshes the page, the new page
automatically scrolls down to same position. However, this automatic
scrolling does NOT happen if the user has scrolled over towards the
right side.

Is there a setting that needs to be adjusted to get this to happen? Or
something I need to do in the page?

FWIW, I'm trying to come up with a script that will pass the
..scrollTop and .scrollLeft properties back to the server on a refresh
(and then use .scrollTo to position the new page) but I'm hoping there
might be a simpler way.

Any suggestions?

Thanks.
 
Y

Yann-Erwan Perio

Martin said:
I have a web page (IE only; intranet only) that is both wider and
longer than the browser window. I've noticed that if the user has
scrolled the page DOWN and then refreshes the page, the new page
automatically scrolls down to same position. However, this automatic
scrolling does NOT happen if the user has scrolled over towards the
right side.
FWIW, I'm trying to come up with a script that will pass the
.scrollTop and .scrollLeft properties back to the server on a refresh
(and then use .scrollTo to position the new page) but I'm hoping there
might be a simpler way.

Since the full process is initiated by javascript, you should rather use
client-side ways of state keeping, for instance cookies or frames - you
could also consider IE behaviors (.htc files).

There's also the following old IE thing (navigator expando), which runs
happily in my current IE; that's probably more a hack than anything, but
since it's been here for years it might as well be used, for instance as
a js include - to be tested accordingly though, I seem to remember it
crashing upon browser closing, but cannot remember the specifics of the
test I tried then (long ago!).


<script type="text/javascript">
if(window.attachEvent) {
window.attachEvent(
"onbeforeunload",
function() {
navigator.scrollLeft=(
document.compatMode &&
document.compatMode.indexOf("CSS")!=-1 &&
document.documentElement || document.body
).scrollLeft;
}
);

window.attachEvent(
"onload",
function() {
if (typeof navigator.scrollLeft!="undefined")
scrollBy(navigator.scrollLeft);
}
);
}

//test
for(var ii=0,s="";ii++<100||document.write(s);s+=ii);
</script>


HTH
Yep.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top