As you travel from one Web site to another, most browsers record the URLs you visit in a history buffer, allowing you to return to them at any time with a single click. This history buffer is accessible to you via the History object, which exposes methods and properties for moving forward and backward through the list of recently-accessed URLs.
In order to access the last URL in the, you would use the history.back() method (equivalent to hitting the browser's "Back" button),
while the history.forward() method lets you access the next URL in the history list (equivalent to hitting the browser's "Forward" button).
Here's an example which illustrates how these two methods can be used to build a simple navigation toolbar:
You can obtain the total number of items in the history list through the History object's "length" property, as below:
You cannot access the elements of the history list directly. You can, however, tell the browser to go to a particular URL from the history list with the history.go() method, which accepts an offset indicating which URL in the history list to go to. In this system, the current URL is always 0, meaning that you can go one step back with the following code:
Which is equivalent to the following:
Finally, note that the History object is limited to storing URLs that have been visited in that window itself. To access history items in other windows, use the window name as prefix.