The history property of the window object refers to the history object for the window. Using history in JavaScript you can go back to the previous browsing history.
The history object models the browsing history of a window as a list of document and document states and the length property of the history object specifies the number of elements in the browsing history list.
The history object has back() and forward() methods that behave like the browser's back and forward buttons do, they make the browser go backward or forward one step in its browsing history.
history.back(); // Go back to the browsing history
history.forward(); //Go forward to the browsing history
You can create buttons to navigate browsing history back and forward using the following code.
Preview:
A third method, go(), takes an integer argument and can skip any number of pages forward or backward in the history list.
history.go(-2) //go back 2, like clicking the back button twice
You can create buttons to navigate browsing history two step back using the following code.
Preview:
Using history.go() method, if you want to go forward, can use positive arguments and if you want to go back, can use negative argument and the number used on the argument represents how many steps to go back or forward.
For example, if you want to go two step forward to the browsing history, can use history.go(2); and if you want to go three step backward to the browsing history, can use history.go(-3);
If a window contains child windows such as
The history object models the browsing history of a window as a list of document and document states and the length property of the history object specifies the number of elements in the browsing history list.
The history object has back() and forward() methods that behave like the browser's back and forward buttons do, they make the browser go backward or forward one step in its browsing history.
history.back(); // Go back to the browsing history
history.forward(); //Go forward to the browsing history
Creating Buttons for History Back and Forward
You can create buttons to navigate browsing history back and forward using the following code.
value="Go Forward"onclick="history.forward();">
Preview:
A third method, go(), takes an integer argument and can skip any number of pages forward or backward in the history list.
history.go(-2) //go back 2, like clicking the back button twice
Creating Buttons for History Back and Forward for Specific Page
You can create buttons to navigate browsing history two step back using the following code.
value="Go Back 2" onclick="history.go(-2);">
Preview:
Using history.go() method, if you want to go forward, can use positive arguments and if you want to go back, can use negative argument and the number used on the argument represents how many steps to go back or forward.
For example, if you want to go two step forward to the browsing history, can use history.go(2); and if you want to go three step backward to the browsing history, can use history.go(-3);
If a window contains child windows such as