html/javascript help

  • Started
  • Last post
  • 5 Responses
  • JamesBoynton

    Hey guys

    I have 100+ pages which all have 'back' and 'next' buttons. Is there anyway using javascript of something that i dont have to go through each page and manually set the links? The pages are titled 1.html, 2 html etc etc.

    I know its a long shot but i thought id ask.

    Cheers

    James

  • Stugoo0

    are all the pages just straight html?

    What about a script that detects what the page is called(obviously you would have to keep them numeric) make that a variable then output previous -1 then next+1 on that variable?

    would that work ?

  • rafalski0

    I guess that could be easily done in php, JS would work too, but would be easy to break (and prolly wouldn't get indexed by search engines). Up to 30 minutes of work for a php (or other server side lang) person imo.

  • JamesBoynton0

    Perfect, cheers guys, will take another look online.

    Thanks again

  • mimeartist0

    yeah... if you choose to use php it is really simple for each page to know where it has come from, and where it should go

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