JavaScript question

At the top of every html page I have a navigation bar. Now, I would like to use javascript for the next and previous page image buttons, so I don't have to link every page to the image buttons myself and by making a list of pages I can easily change the order.

<!--
       function MakeArray(n) {
                this.length = n;
                for (var i =1; i <= n; i++) {
                        this[i] = 0}
                        return this
                        }

        Next = new MakeArray(4);

        Next[0] = "intro.html"  //-----example pages------
        Next[1] = "main.html"
        Next[2] = "next.html"
        Next[3] = "help.html"
        page = 0

        function Turnpage(vector) {
                Next[page]= top.location.href
                if (vector == 'next') {
                        if ( page == 3) {
                                page = 0
                                top.location = Next[page]
                                }
                        else {
                                ++page
                                top.location = Next[page]
                                }
                        }
                else {
                        if (page == 0 ) {
                                page = 3
                                top.location = Next[page]
                                }
                        else {
                                --page
                                top.location = Next[page]
                                }
                        }
        }

// -->

This is how far I came myself, but this doesn't work since every time the script is loaded into a new page it starts counting all over again. I wanted to use the current location.href. By knowing the current location it should be known what the next and the previous page is. How do I do this???

Thanks,
Anita van Dijk
avandijkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rsfCommented:
Hoi anita je kunt gebruik maken van het history object.
history.back() is de back functie
history.forward() is de forward functie
history.go(aantal_pagina's) is de functie waarmee je aan kunt geven hoeveel pagina's je voor of achteruit wilt. Zet een - om achteruit te gaan.

Als dit niet precies is wat je zoekt zet dan nog even een comment.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
avandijkAuthor Commented:
Dit is niet wat ik zoek. Het gaat er juist om dat het niet altijd om de history bladzijde gaat. Het gaat erom dat een gebruiker kris kras kan navigeren maar ook op volgorde. Als een gebruiker dan zomaar ergens naartoe springt moet het vanaf daar mogelijk zijn om de vantevoren vastgelegde volgorde weer aan te houden (zowel vooruit als achteruit) door de juiste URL uit een lijst met URLs te halen ofzo.
0
rsfCommented:
Het onderstaande script is wat je wilt. Je kunt nu 5 pagina's maken met de namen in de nextpage array. In elk van deze pagina's kun je dit script zetten. Door op de back and forward button te klikken kun je vooruit of achteruit gaan. Ik heb dit getest in Netscape 3.

<html>
<head>
<title>demo</title>
<script language="Javascript">
nextpage = new Array("intro.html", "navigatie.html","main.html", "next.html", "help.html");

function getfilename() {
      filename= "";
  for (i= document.location.pathname.lastIndexOf("/")+1; i<= document.location.pathname.length; i++) {
        filename+= document.location.pathname.charAt(i);
      }
      return filename;
}

function goforward() {
  filename= getfilename();
      for (i= nextpage.length; i>= 0; i--) {
            if (filename== nextpage[i]) {
              if (i+1< nextpage.length && nextpage[i+1]!= null) {
                    document.location.href= nextpage[i+1];
                        break;
                  }
            }
      }
}

function goback() {
  alert(document.location.href.toString());
  filename= getfilename();
      for (i= nextpage.length; i>= 0; i--) {
            if (filename== nextpage[i]) {
              if (i-1>= 0 && nextpage[i-1]!= null) {
                    document.location.href= nextpage[i-1];
                        break;
                  }
            }
      }
}
</script>
</head>
<body>
<form>
<input type=button onclick="goback()" value="back">
<input type=button onclick="goforward()" value="forward">
</form>
</body>
</html>
0
avandijkAuthor Commented:
Harstikke bedankt, een hele goede aanvulling op de oplossing die ik zelf inmiddels gevonden had.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.