Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JavaScript question

Posted on 1997-09-11
4
Medium Priority
?
197 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:avandijk
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
rsf earned 0 total points
ID: 1270321
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
 

Author Comment

by:avandijk
ID: 1270322
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
 
LVL 1

Expert Comment

by:rsf
ID: 1270323
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
 

Author Comment

by:avandijk
ID: 1270324
Harstikke bedankt, een hele goede aanvulling op de oplossing die ik zelf inmiddels gevonden had.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question