window.history object stores information about the history of the window.
history is a global object, so we can use it with and without referring to
history both are valid.
Browsers keep data about the history of the current window. All the pages visited are stored in a list.
history object has some properties and methods. The following session will show you how to get information about the user's browser history.
Get Number of Pages Visited in One Session
length property of the
history object gives us the number of pages visited by the user in current the tab, including current page.
Window History : Going To Previous Page
back() method of the global
history object loads the previous URL to the window.
When you click the back arrow button in browse
history.back() method is fired.
Window History : Going To Next Page
forward() method of the global
history object loads the next URL to the window.
When you click the next arrow button in browser
history.forward() method is fired.
Jump To Any Page From The History List
go() method of global
history objects can direct us to any number of pages from the list. The page number we want to visit is passed as an argument in the function.
The passed number can be positive, negative and zero. Zero represents the current page, negative number represents previous pages and positive number represents next pages.