Introduction
The history object is an array of the history of the pages that have been loaded. The window.history object represents the user's history list of viewed web pages. The amount of information you can get from the history object is limited. The properties and methods of the history object are limited since there is no way to determine the position of the current URL in the history object.
The history.forward() method loads the next URL in the history list. It is equivalent to clicking the forward button in the browser. The second method of history is history.back() method that loads the previous URL in the history list. It is equivalent to clicking the Back button in the browser.
The following example shows browser history in JavaScript. In this example we use the two functions Back() and Forward(). In the Back() function we call history.back() method. It loads the previous URL in the history list. In the Forward() function we call history.forward() method. It loads the next URL in the history list.
Complete Program
Window_History_Demo.html
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title></title>
- <script type="text/javascript">
- function Back()
- {
- window.history.back();
- }
- function Forward()
- {
- window.history.forward();
- }
-
- </script>
- </head>
- <body>
- <p style="font-size: large; font-weight: bold">
- Click on button for show Window History</p>
- <p style="font-size: large; font-weight: bold">
-
- <input id="Button1" style="font-weight: bold" type="button" value="Back" onclick="Back()" />
-
- <input id="Button2" style="font-weight: bold" type="button" value="Forward" onclick="Forward()" /></p>
- </body>
- </html>
Output
For more information, download the attached sample application.