How to use history.go(0) In JQuery

The history.go() method loads a URL from the browser’s history depending on the parameter passed to it. If the parameter passed is ‘0’, it reloads the current page.

Syntax:

history.go(0);

Example:

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        How to refresh a page
        using jQuery?
    </title>
 
    <script src=
"https://code.jquery.com/jquery-3.3.1.min.js">
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                history.go(0);
                alert('Reloading Page');
            });
        });
    </script>
</head>
 
<body>
    <center>
        <h1 style="color: green">
            w3wiki
        </h1>
 
        <b>
            How to refresh a page
            using jQuery?
        </b>
 
        <p>
            w3wiki is a computer science
            portal with a huge variety of well
            written <br> and explained computer
            science and programming articles,
            quizzes and interview questions.
        </p>
 
        <button type="button">
            Button to Reload page
        </button>
    </center>
 
</body>
 
</html>


Output:

How to refresh a page using jQuery?

In jQuery, you can use simple methods to refresh a page, ensuring that the current content is reloaded for a fresh experience. we have some common methods to refresh our page.

Here are several Approaches

Table of Content

  • Using the location.reload()
  • Using history.go(0):
  • Using location.replace with the current page:

Similar Reads

Using the location.reload()

The location.reload() method reloads the current web page emulating the clicking of the refresh button on the browser. The optional true parameter passed to the method is used to force the page to load from the server and ignore the browser cache....

Using history.go(0)

...

Using location.replace() with the current page

The history.go() method loads a URL from the browser’s history depending on the parameter passed to it. If the parameter passed is ‘0’, it reloads the current page....