Window History In JavaScript

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
  1. <!DOCTYPE html>  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <title></title>  
  5.     <script type="text/javascript">  
  6.        function Back()  
  7.         {  
  8.             window.history.back();  
  9.         }  
  10.        function Forward()  
  11.         {  
  12.             window.history.forward();  
  13.         }  
  14.    
  15.     </script>  
  16. </head>  
  17. <body>  
  18.     <p style="font-size: large; font-weight: bold">  
  19.         Click on button for show Window History</p>  
  20.     <p style="font-size: large; font-weight: bold">  
  21.          
  22.         <input id="Button1" style="font-weight: bold" type="button" value="Back" onclick="Back()" />  
  23.        
  24.         <input id="Button2" style="font-weight: bold" type="button" value="Forward" onclick="Forward()" /></p>  
  25. </body>  
  26. </html> 
Output 
 
result.jpg
 
For more information, download the attached sample application.


Similar Articles