The window.history object stores the browsing history of the user’s session.
The history object can be used without the window prefix.
To safeguard user privacy, JavaScript has restricted access to this object.
Some available methods include:
The history.back() method navigates to the previous URL in the history list, similar to clicking the Back button in the browser.
Create a button on a page that navigates back:
<html> <head> <script> function goBack() { window.history.back() } </script> </head> <body> <input type=”button” value=”Back” onclick=”goBack()”> </body> </html> |
The result of the code above will be:
The history.forward() method navigates to the next URL in the history list, similar to clicking the Forward button in the browser.
Create a button on a page that navigates forward:
<html> <head> <script> function goForward() { window.history.forward() } </script> </head> <body> <input type=”button” value=”Forward” onclick=”goForward()”> </body> </html> |