Solved

JavaScript question

Posted on 1997-09-11
4
190 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Parallax 1 38
what is the difference between currentTarget and target 4 35
Angular.js example vocabulary extensions 5 34
jQuery not working on ELSE... why? 2 24
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

867 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

12 Experts available now in Live!

Get 1:1 Help Now