history and location Objects

This simple form allows us to navigate to different documents by using the back() and forward() history Methods instead of using the browser's buttons.

<FORM NAME="buttonbar">
     <INPUT TYPE="button" VALUE="Back" onClick="history.back()">
     <INPUT TYPE="button" VALUE="JS - Home" onClick="location.href='../index.htm'">
     <
INPUT TYPE="button" VALUE="Next" onClick="history.forward()">
</FORM>

You could also write history.go(-x) and history.go(x)

"history.go(##)" denotes movement through your history file. That's the file that keeps a record of everywhere you've been during that particular web browsing session. (1) sends it forward one step, (-1) sends you backwards one step. If you'd like, you can raise or lower those numbers. Setting it to (-4) will take your user back four pages if he or she has that many page in their history file. If not, then the button will not function.

location.href='../index.htm' - takes us directly to the index.htm page.

Number of Web pages visited during this Session

<SCRIPT LANGUAGE="JavaScript">

function showCount() {
     var histCount = history.
length;

     if (histCount > 5) {
         
alert("My, my, you've been busy. You have visited " + histCount + " Web pages so far.");
     }
     else {
         
alert("You have been to " + histCount + " Web pages this session.");
     }
}

</SCRIPT>

<FORM>
     <
INPUT TYPE="button" NAME="activity" VALUE="My Activity" onClick="showCount()">
</
FORM>

NOTE: The history Object is an Array of URLs. Like all Arrays, it has a length Property that specifies the number of elements in the Array. So history.length is the number of elements in the history Array.