How to Reload a Web Page with Javascript


In this article, we show how to reload a web page with Javascript.

So, depending on your web application, you may need the page to programmatically reload, or refresh itself.

Javascript can reload a page using the reload() function.

If the reload() function is called on the window object, then the page will reload.

The window object represents the current page, with its current URL. Therefore, if you call the reload() function on the window object, the whole page will be reloaded.

So in order to reload a page with Javascript, we use the following code shown below.

So we really call the reload() function on the window.location attribute.

The window itself just represents the entire page, kind of like just the physical object of the page. What we really want to reload the page's URL. The current page's URL is found in window.location. So for this page, window.location, would be equal to,

This URL is really what we want to refresh, not the document window object. It's really the URL>

So by using the line, window.location.reload(), we are able to reload our page.

As a demonstration, if you click the following button below, the window.location.reload() function will be run. You will be able to see that the page reloads, or refreshes, upon clicking the button.

You should notice the reload that occurs when the button is clicked.

And this is how to reload a web page with Javascript.

Related Resources

How to Hide an HTML Element with jQuery

How to Show an HTML Element with jQuery

How to Create a Comment System in Which Only One Reply Comment Box Can Be Open At Once with jQuery

How to Upload a File with the Click of an Image with jQuery

HTML Comment Box is loading comments...