Different ways to refresh or reload page using jQuery

In this post, I will show you the different ways using which you can reload or refresh the webpage using jQuery. The first method is nothing to do with jQuery. It is a HTML tag which you need to put in the head section of your page and your page will get refreshed automatically after specified interval.

<meta http-equiv="refresh" content="10">

The meta tag with "http-equiv" is used to refresh the page. This attribute tells the browser that this meta tag is sending an HTTP command rather than a standard meta tag. Refresh is an actual HTTP header used by the web server.The content attribute in the tag is having value in seconds. As per the above code, it is set to 10, which means after 10 seconds your page will get refreshed or reloaded.

Earlier I had posted about Redirect to another page after X seconds wait, Redirect user to another web page using jQuery, Get URL Parameters using jQuery and How to force browser to reload the images.

You can also use jQuery to refresh/reload the page automatically. See below jQuery code.

function ReloadPage() { 
   location.reload();
};

$(document).ready(function() {
  setTimeout("ReloadPage()", 10000); .
});

location.reload() will reload the page again. The advantage of location.reload() is that it works with all the major browsers.

If you want to reload the page on click of button, then you can call location.reload() on button click event. See below jQuery code.

$(document).ready(function() {
     $('#btnReload').click(function() {
             location.reload();
       });
}); 

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...