How to Refresh a Page Using Jquery and Javascript

In this tutorial, learn how to refresh a page on button click using jQuery or javascript. Create simple page refresh or refresh the page after a time delay in seconds with jQuery.

The page refresh may require sometime when you update content and show the result. The result will be displayed after you refresh the page on button click. You may also like to read how to redirect to another page using jQuery.

How to Refresh a Page Using jQuery

To refresh a page on button click using jQuery, you have to use location.reload(). This refresh the page with the jQuery click event of the button.

Output



The above example contains the button and the script to refresh the page. Click the above button to refresh a page using jQuery. This performs a refresh of the page immediately on click of the button.

However, if you want to refresh the page after some seconds, please read further.

Refresh a Page Using Javascript

In addition to the above jQuery method, you can also refresh a page using javascript. This requires a function which contains the code location.reload();. The example contains the button with the onclick event.

The onclick attribute contains the function for the page refresh.

Output



Click the above button to refresh the page immediately using javascript. The function given above executes on click of the button element.

If you want to refresh the page after some time delay in seconds, please read further.

Add Time Delay in Seconds For Page Refresh Using jQuery

To refresh the page after some time delay on the button click. You have to use the setTimeout() of jQuery to add a time delay. It also contains the code location.reload() to execute on button click.

Output



The above example contains the button which refreshes the page on click. It takes 5 seconds after which the page refresh code executes to refresh a page. This is useful to execute your code and refresh the page after some time delay.

You can change the time delay of 5 seconds for the above example. Replace the time delay given above as per your requirement.

Hope, you like the tutorial of how to refresh a page on button click using jQuery or javascript. If you have any query regarding the tutorial, please comment below.

Also tell me, which method are you using to refresh the page with the delay or without.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.