Web Development Tutorials


The history Object

The history object is considered part of window object and contains the URLs visited by the user. The history object is an array that holds the pages that have been loaded by the browser. The history does not provide a way to determine what URLs are in the browser's history. The general format of the window.history object or more simply history is shown below:



Figure 7-25. General format to reference properties of the history object.

For each of the following properties, its value is shown for the browser you are using to view this page. These properties are read and displayed during page load with inline scripts in the format

document.getElementById("Output").innerHTML = history.property;
Property Description and Current Setting
length The number of URLs in the history object:

The history object includes the following methods. The (history) method is accessible like the object properties


Figure 7-26. Method of the history object.

Method Description and Current Setting
back() Goes back one step in the URL history. history.back()
forward() Goes forward one step in the URL history. history.forward()
go(position) Goes forward or backwards the specified number of steps in the URL history
go(substring) Goes to the most recent URL in the history that contains the substring

TOP | NEXT: The navigator Object