restoring scroll position

D

David McDivitt

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;
}
 
J

Julian Turner

David McDivitt wrote:

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

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
 
D

David McDivitt

From: "Julian Turner said:
Date: 5 Dec 2005 08:26:10 -0800
Lines: 21


David McDivitt wrote:

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

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


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

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top