Different ways to refresh or reload page using jQuery
Nov 28, 2011
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.
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.
You can also use jQuery to refresh/reload the page automatically. See below jQuery code.
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.
Hope this post will help you!
<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.
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(); }); });
Hope this post will help you!
Share
Labels:
jQuery,
jQuery Tips,
Performance