restoring scroll position

Discussion in 'Javascript' started by David McDivitt, Dec 5, 2005.

  1. 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;
    David McDivitt, Dec 5, 2005
    1. Advertisements

  2. David McDivitt wrote:

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


    Julian Turner, Dec 5, 2005
    1. Advertisements

  3. Thanks! That fixed my problem. It had been working perfectly, then started
    acting screwy and I couldn't figure out what I did.
    David McDivitt, Dec 5, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.