JavaScript History Object

  • History Object
  • Properties of History Object
  • Methods of History Object
  • Example of History Object

The history object in JavaScript symbolizes a collection of URLs that the user has navigated through. Utilizing this object allows you to access earlier pages, move forward, or navigate to any specific page in the browsing history.

The history object is a property of the window, meaning it can be accessed using:

Example

window.history
Example

history

Property of JavaScript history object

There are only 1 property of history object.

No. Property Description
1 length returns the length of the history URLs.

Methods of JavaScript history object

There are only 3 methods of history object.

No. Method Description
1 forward() loads the next page.
2 back() loads the previous page.
3 go() loads the given page number.

Example of history object

Let’s see the different usage of history object.

Example

history.back();//for previous page

history.forward();//for next page

history.go(2);//for next 2nd page

history.go(-2);//for previous 2nd page

Input Required

This code uses input(). Please provide values below: