html/javascript help

Out of context: Reply #5

  • Started
  • Last post
  • 5 Responses
  • SeanM0

    The way that usually handle this is to maintain an ar

    ray(sequence_array) within a JS script, say sequence.js. sequence js is included within every

    page. The array would take the form of ["mypage1.htm", "someotherpage.htm",

    "andanotherpage.htm"...].(This could also be maintained within an xml file and then parsed but

    sometimes the array is just more pragamatic). If you are using pure js, no js libs(prototype, jquery etc.) then provide the following to your body tag of all pages

    included in the sequence. . (see jquery's document.ready for

    something cool) Within sequence.js implement your initSequence function so that it extracts the

    query string from the current page(document.location.href), substrings that value to extract the actual file name of the page("mypage1.htm",

    "someotherpage.htm" etc.), loops over sequence_array evaluating the value of each iteration to see if it matches the string

    previously obtained from the document.location.href substring. If you find a match then you know

    the index number of the current value within sequence_array. Therefor you can sequence_array[i-1]

    to get the previous value and sequence_array[i+1] to get the next value. Your will have to handle

    the two bookend conditions where sequence_array[i-1] would return null for the first page in the

    sequence and sequence_array[i+1] would return null for the last page in the sequence. So,

    assuming your prev and next are hyperlinks, once you have retrieved your previous and next values

    you can apply them via document.getElementB

    yId("myPrevLink").href=sequence... And

    document.getElementById("myNextL... There are many other ways to

    skin this cat but this is just how I have done it in the past.

View thread