How to Refresh a page using JavaScript

I am again with a new JavaScript article for browsers. In this article, I am going to let you know how you can refresh the current web page with JavaScript code.

So let’s continue to learn…

Also, read: Generate QR code in JavaScript in an easy way

First of all, let me introduced you to the location reload() method. This method will help us to reload the current web page.

Using the location reload() method is very easy. Just calling this method will refresh the current page. So if you want to refresh the web page, all you need to do is just to put one line of JavaScript code that is given below:

location.reload();

That’s it. It will do the task. Actually, it is actually reloading the current document. This method is working as same as your browser refresh button does.

Well, you should also know that, by default, the JavaScript reload method refresh the page from the cache. But sometime you may need to reload a web page from the server. So in that case, you can set the forceGet parameter to true.

Actually, the location reloads method can take a parameter which is the forceGet parameter. It is set to false in default. But if you set it to true, it refreshes from the server-side. Below is the syntax:

location.reload(forceGet)

So below is the JavaScript code to refresh the web page from the server:

location.reload(true)

 

I hope, you get the solution and implement it in your JS program. Happy coding…

Leave a Reply

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