Here you will learn about history objectproperties and methods, length, current, next, previous properties, back(), forward() and go() methods along with syntax and examples.
General syntax of history property of Window Object:
Property of History Object
The length property of the history object returns the number of elements in the history list.
This property contains the complete URL of the current History entry.
The previous property of history object contains the complete URL of the previous element in the History list. This functionality or the URL visited is the same as pressing the back button or menu.
The next property of history object contains the complete URL of the next element in the History list. This functionality or the URL visited is the same as pressing the forward button or menu.
Methods of History Object
There may be scenarios where the programmer wishes to load the previous URL present in the history list. In this case, the programmer can make use of the back() method of the history object. The back() method of the history object takes the user to the previous page. The functionality results in the same as pressing the back button of the browser.
The forward() method of the history object loads the next URL in the History list. The functionality results are the same as pressing the forward button of the browser.
If the programmer wishes to load a specified URL from the History list, then the go method of history object can be used.
history.go(number); OR history.go(URL);