What is the use of history object?

What is the use of history object?

The history object is a type of JavaScript object. It is a part of the window object and is accessed through the window.history property.

The history object can be used to access all the URLs that are visited by the user within the browser window. It can be written without the window prefix.

In order to protect the privacy of the users, there are limitations to how JavaScript can access this object. Some of the ways that JavaScript can access it is via the following methods:

  • history.length – returns the number of URLs in the history list of the current browser window.
  • history.back() – same as clicking back in the browser. It loads the previous URL in the history list.
  • history.forward() – same as clicking forward in the browser. It loads the next URL in the history list.
  • history.go() – same as entering a specific URL. It loads a specific URL from the history list.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.