The Ugly JavaScript Book - Chapter Nine

Chapter Nine
Navigating the "Go" List


JavaScript control of the Browser is accomplished by reading and then navigating the visitor's "Go" or "History" list. It is among the things that are really a hold-over from the early days of browsers.
     With click and hold (or right button click) the typical surfer neither wishes to click on a link that (for all he/she knows) will cause a reload upon return to, say, a Home Page document, nor to click on a button for the same purpose.
     The surfer knows that it is faster to click back or click the "Back" button on the browser - another anachronism from the early days.
     Therefore, this is an entire chapter that I recommend you skip unless you are programming .cgi scripts and wish to provide backward navigation that will skip over every other page in the "Go" or "History" list.
     At the top of your screen, you will see an item labelled "Go". This is your History list. It shows the last ten or so HTML pages you have visited.
     It is restarted each time that you restart your Netscape¨ browser.
     Why is it labeled "Go" instead of "History"? Dunno. AinŐt real consistent. But as the newly enthroned resident guru, youŐll need to remember that the two are talking about the same thing.
     Now, there are three different ways to use the built-in JavaScript functions to move a visitor to other pages from the page he or she is now viewing.

history.back();
     This call takes the visitor back one step in the "Go" or "History" list active during this session. It is similar to the history.go(-1) call.
     If the user were to click the "Back" button at the top of his/her browser, the same thing would happen as happens when you use this call.
     But you are probably better off in most cases to avoid using this call, especially if you are using frames.

history.forward();
     This call takes the visitor forward one step in the "Go" or "History" list active during this session. It is similar to the history.go(+1) call.
     If the user were to click the "Forward" button at the top of his/her browser, the same thing would happen as happens with this built-in function.
     If there is no "forward" item in the "Go" list, nothing happens.
     If for some reason you wish to emulate buttons already present at the top of the browser using JavaScript, this is how you do it:

<FORM>
<INPUT TYPE="button" VALUE=" Back " onClick="history.back()">
<INPUT TYPE="button" VALUE=" Forward " onClick="history.forward()">
</FORM>

history.go(x||variable);
     Moves forward or backward in the "Go" or "History" list active during this session.
     x is number or a variable equal to a number equal to the number of steps you wish to move up or down the "Go" or history list.
     A minus number takes you back, a positive number takes you forward in the "Go" or "History" list for this session. If you set steps equal to 0, this function will reload the current page.
     variable is a literal URL or a string set equal to all or part of a URL in the "Go" or history list.

Links: Introduction | Chapter One | Chapter Two | Chapter Three | Chapter Four | Chapter Five | Chapter Six | Chapter Seven | Chapter Eight | Chapter Ten | Chapter Eleven | Chapter Twelve | Chapter Thirteen | Chapter Fourteen | Chapter Fifteen | Chapter Sixteen | Chapter Seventeen | Chapter Eighteen | Chapter Nineteen | Chapter Twenty | Chapter Twenty-one | Chapter Twenty-two | Chapter Twenty-three | Appendix A | Appendix B | Appendix C | Appendix D | Cover
This free virtual book provided courtesy of:
AutoScripter(tm), the site for professional Web Designers and Developers and
WebWalker Virtual Press, virtual publishing on the Web since 1994
Other free e-books from WebWalker: The All American Terrorists | The Gnomes of Jost | For the Love of Entropy | The Trees of Kratva | The Arch of Rain Magicians | Lightshow | The Black Mancutters Guild | The Septoracle

© Copyright 1997, 1999, 2000, 2001 John H. Keyes
editor@jorika.com