jQuery

How to refresh a page with jQuery

In this tutorial, we are going to see how to refresh a page with jQuery. You can simply use JavaScript’s location.reload() method to refresh the page. This method optionally accepts a Boolean parameter of true or false. If the true parameter is specified, the page is always refreshed from the server. However, if it is false (the default) or not specified, the browser can refresh the page from its cache.
 

How to refresh a page with jQuery
$(document).ready(function() {
    $("button").click(function() {
        location.reload(true);
    });
});
<button type="button">Refresh the page</button>

If you want to reload a page after X seconds, you can simply use setTimeout. Example refresh a page after 5 seconds.

setTimeout(function() {
    location.reload();
}, 5000);

You can do the same with JavaScript. You don’t need jQuery for this. See the following example:

function reload() {
    location.reload(true);
}
<button type="button" onclick="reload();">Refresh the page</button>
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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