How to refresh a page using jQuery?

Method 1: 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.

Syntax:

location.reload(true)

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to refresh a page
        using jQuery?
    </title>
      
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
      
    <b>
        How to refresh a page
        using jQuery?
    </b>
      
    <p>
        GeeksforGeeks is a computer science
        portal with a huge variety of well
        written and explained computer science
        and programming articles, quizzes
        and interview questions.
    </p>
      
    <button type="button">
        Button to Reload page
    </button>
  
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                location.reload(true);
                alert('Reloading Page');
            });
        });
    </script>
</body>
  
</html>                    

chevron_right


Method 2: Using history.go(0): The history.go() method loads a URL from the browsers history depending on the parameter passed to it. If the parameter passed is ‘0’, it reloads the current page.

Syntax:

history.go(0);

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Method 3: Using location.replace with the current page: The location.replace() method can be used be passed with the location.pathname as a parameter. The location.pathname returns the current url and passing that on to location.replace() reloads the current page.

Syntax:

location.replace(location.pathname);

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to refresh a page
        using jQuery?
    </title>
      
    <script src=
    </script>
</head>
  
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
      
    <b>
        How to refresh a page
        using jQuery?
    </b>
      
    <p>
        GeeksforGeeks is a computer science
        portal with a huge variety of well
        written and explained computer science
        and programming articles, quizzes
        and interview questions.
    </p>
      
    <button type="button">
        Button to Reload page
    </button>
  
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                location.reload(true);
                alert('Reloading Page');
            });
        });
    </script>
</body>
  
</html>                    

chevron_right


Output:

  • Before clicking the button: before-reload
  • After clicking the button: after-reload


My Personal Notes arrow_drop_up

Technical Writer Lets have an update

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.