JavaScript History Object

The JavaScript History Object is property of the window object.

Properties

  • current - The current document URL.
  • length - The number of entries in the history object.
  • next - The URL of the next document in the history object.
  • previous - The URL of the last document in the history object.

Methods

  • back() - Go to the previous URL entry in the history list. This does the same thing as the browser back button. The following HTML code creates a back button:
    <FORM>
    <INPUT TYPE="button" VALUE="Go Back" onClick="history.back()">
    </FORM>
    

    Here is the button:

  • forward()- Go to the next URL entry in the history list. This does the same thing as the browser forward button. This is only effective when there is a next document in the history list. The back function or browser back button must have previously been used for this function to work. The following HTML code creates a forward button:
    <FORM>
    <INPUT TYPE="button" VALUE="Go Forward" onClick="history.forward()">
    </FORM>
    

    Here is the button:




  • go(relPos | string) - This function will accept an integer or a string. If an integer is used, the browser will go forward or back (if the value is negative) the number of specified pages in the history object (if the requested entry exists in the history object). The following example will move the browser back one page.

    <FORM> <INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"> </FORM>