Connecting Tech Pros Worldwide Help | Site Map

restoring scroll position

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 5th, 2005, 03:15 PM
David McDivitt
Guest
 
Posts: n/a
Default restoring scroll position

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


  #2  
Old December 5th, 2005, 03:35 PM
Julian Turner
Guest
 
Posts: n/a
Default 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

  #3  
Old December 5th, 2005, 04:35 PM
David McDivitt
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.