Connecting Tech Pros Worldwide Forums | Help | Site Map

restoring scroll position

David McDivitt
Guest
 
Posts: n/a
#1: Dec 5 '05
Rather than have several different pages, an app was designed to have
different sections, all on one page. To get to the different sections the
browser is scrolled down. It may take several submits before everything gets
filled out correctly. The user complained because the page would not scroll
to the previous position, code was installed to save and restore the page
position, but it doesn't always go to the same place. Sometimes it does.
Sometimes it doesn't. Two text boxes are used to save position, and the page
is regenerated with x and y as literals by the server. The problem seems to
be what values are saved as the page is submitted. A better idea or fix
would be appreciated. Thanks


function windowRestore() {
var x=<%="0"+xPos%>;
var y=<%="0"+yPos%>;
if (top.opera && (typeof window.pageYOffset != 'undefined')) {
window.pageXOffset = x;
window.pageYOffset = y;
}
else if (window.document.compatMode && (window.document.compatMode !=
'BackCompat')) {
window.document.documentElement.scrollLeft = x;
window.document.documentElement.scrollTop = y;
}
else window.scrollBy(x,y);
}

function windowSave() {
var x, y;
if (typeof window.pageXOffset != 'undefined') {
x = window.pageXOffset;
y = window.pageYOffset;
}
else {
if ((!window.document.compatMode) || (window.document.compatMode ==
'BackCompat')) {
x = window.document.body.scrollLeft;
y = window.document.body.scrollTop;
}
else {
x = window.document.documentElement.scrollLeft;
y = window.document.documentElement.scrollTop;
}
}
document.ArtRec.windowXPos.value = x;
document.ArtRec.windowYPos.value = y;
}


Julian Turner
Guest
 
Posts: n/a
#2: Dec 5 '05

re: restoring scroll position



David McDivitt wrote:

[snip]
[color=blue]
> var x=<%="0"+xPos%>;
> var y=<%="0"+yPos%>;[/color]

This could be creating octal valuues in the resulting page, at least
some of the time. Hence the variation.

I.e. if you precede a number with 0, Javascript first attempts to read
it as an "octal" number:-

alert(017); 15 (Decimal)
alert(097); 97 (Decimal, as cannot be read as an octal number).

Regards

Julian

David McDivitt
Guest
 
Posts: n/a
#3: Dec 5 '05

re: restoring scroll position


>From: "Julian Turner" <julian@baconbutty.com>[color=blue]
>Date: 5 Dec 2005 08:26:10 -0800
>Lines: 21
>
>
>David McDivitt wrote:
>
>[snip]
>[color=green]
>> var x=<%="0"+xPos%>;
>> var y=<%="0"+yPos%>;[/color]
>
>This could be creating octal valuues in the resulting page, at least
>some of the time. Hence the variation.
>
>I.e. if you precede a number with 0, Javascript first attempts to read
>it as an "octal" number:-
>
>alert(017); 15 (Decimal)
>alert(097); 97 (Decimal, as cannot be read as an octal number).
>
>Regards
>
>Julian[/color]


Thanks! That fixed my problem. It had been working perfectly, then started
acting screwy and I couldn't figure out what I did.

Closed Thread