JavaScript Tip of the Week: Main01.html | 2 | WebReference

JavaScript Tip of the Week: Main01.html | 2

The most imporant frame in the tour is the bottom frame; in this case called tour_guide.html This is where the forward and back buttons are placed, and where all of the code is. The forward button's code looks like this:
    <A HREF = "JavaScript:tour(2);">
    <IMG SRC = "forward.gif"></A>

and the back button's code looks like this:
    <A HREF = "JavaScript:tour(1);">
    <IMG SRC = "back.gif"></A>
The numbers 1 and 2 are important because they tell the function below which way to move the tour. If the forward button is pressed, it sends the function tour() 2. When tour() reveives 2, it adds one to the part variable, which determines which part of the tour to frames should be on. So part is increased by 1, and the the function tour() goes to "part 1" of the tour. When the back button is pressed, it sends tour() 1. When tour receives 1 it decreases part by one, thereby moving the tour back 1 place.
function tour(direct){    
    if (direct == 2){  <-- tour gets 2 and increases part by one
        if (part > 9){ <-- if tour is done, in this case at 9, stop
        part = 9;
    if (direct == 1){  <-- tour gets 1 and decreases part by one
    part = part -1;
        if (part comments01.html
", "main00.html"); } ...
After tour() determines whether it should go forward or backward, it then sends function show_tour the two URLs that it wants the side frame and the main frame to change to. In this case, if the tour is one part 1, it would change the side frame to comments00.html and the main frame to main00.html. This is what show_tour() looks like:
function show_tour(comments_window, main_window){
    parent.frames[0].location = comments_window;
    parent.frames[2].location = main_window;

The first URL sent to show_tour(), comments00.html, is given to varible comments_window, and then the side frame is set to that location. The second URL, main00.html, is given to variable main_window, then the main frame is sent to that locaion.

This process goes for as many parts as you want the tour to have, and is also very easy to use. One thing that can make a tour more usefull is if you use anchors to display a certain section of a page at a time, like in the remote tip tour. Source