history.go(url/number)

The go() method can navigate through the user's history backward or forward. go() accepts an integer representing the number of pages to go backward or forward a its single argument.

A negative number moves backward in history and a positive number moves forward.


//go back one page 
history.go(-1); 
//go forward one page 
history.go(1); 
//go forward two pages 
history.go(2);
 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
    </head> 
    <body> 
        <script> 
            history.go(-1); 


        </script> 
    </body> 
</html>
  
Click to view the demo

The go() method argument can be a string. The browser navigates to the first location in history that contains the given string.

The closest location may be either backward or forward. If there's no entry in history matching the string, then the method does nothing:

 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
    </head> 
    <body> 
        <script type="text/javascript"> 
                    window.history.go("http://www.java2s.com"); 
        </script> 
    </body> 
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    DOM  

History:
  1. The History Object
  2. history.back()
  3. history.forward()
  4. history.go(url/number)
  5. history.length
  6. history.pushState:Adding an Entry to the Browser History