Home Basics JavaScript History Object

JavaScript History Object

The JavaScript history object is used to represent an array of URLs which are visited by the user.

It exposes some methods and properties that let you navigate back and forth through the user’s history, and manipulate the contents of the history stack.

The history object is a window property, so it can be accessed like this:

window.history  or history


Property Description
length returns the length of the history URLs.


Method Description
forward() loads the next page.
back() loads the previous page.
go() loads the given page number.


Here are some examples of the history object


history.back();//for previous page
history.forward();//for next page
history.go(2);//go forward  2 pages
history.go(-2);//go back 2 pages


You may also like