Solved

JavaScript question

Posted on 1997-09-11
4
189 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Harstikke bedankt, een hele goede aanvulling op de oplossing die ik zelf inmiddels gevonden had.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now