PASSWORD RESET

Your destination for complete Tech news

How to refresh a page using javascript?

396 0
< 1 min read

To refresh a page using JavaScript, you can use the location.reload method of the window.location object. The location.reload method reloads the current page from the server, and it has an optional argument that specifies whether to reload the page from the cache or from the server.

Here is an example of how to use the location.reload method to refresh a page:

// Reload the page from the server
location.reload();

// Reload the page from the cache
location.reload(true);

The location.reload method is often used in conjunction with the confirm function to prompt the user to confirm the reload before it is executed. For example:

if (confirm('Are you sure you want to refresh the page?')) {
  location.reload();
}

Note that the location.reload method only works for the current page, and it cannot be used to refresh a different page or to load a new page. If you want to refresh a different page or load a new page, you can use the location.assign method or the location.replace method.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.