JavaScript History forward() Tutorial

In this section, we will learn what the History forward() method is and how to use it in JavaScript.

JavaScript History forward() Method

We know that in a browser window we can move backward and forward to see visited URLs. Now let’s say a user visited our webpage and then moved to another website and all of a sudden returned to our webpage (So now there’s on forward visited page here).

Via the `forward()` method, we can forward the user to that next visited URL.

Note: if there’s no visited website, the method won’t do anything.

History forward() Method Syntax:

history.forward()

History forward() Method Parameter:

The method does not take an argument.

History forward() Method Return Value:

The method does not return a value.

Example: using History forward() method in JavaScript

<!DOCTYPE html>
<html>
   <head>
      <title>JS is fun :)</title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
   </head>
   <body>
    <button onclick="forw()"> Go forward</button>
    <script >
      function forw(){
        history.forward();
      }
    </script>
   </body>
</html>
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies