Solved

JavaScript question

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiflying 2 Input Text On a Table 7 31
html input 8 43
check a checkbox of a checkboxes group in bootstrap 2 45
What if i make webbased alternative for MS Access 5 71
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

830 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