JavaScript

How to refresh a page in Javascript

In this tutorial, we are going to see different methods to refresh a page in Javascript.
 

Using the history object

We can refresh the current page using the method go() of the browser’s history object.

<input type="button" value = "Refresh" onclick="history.go(0)" />
Result
 

Using the method window.location.reload()

We can refresh the current page using the method reload() of the window.location object.

location.reload();
//OR
window.location.reload();

 

Define the meta tag

We can also set the http-equiv meta tag which will automatically refresh the page at a given interval.

<meta http-equiv="refresh" content="1">

This will reload the page after a second. Here content="1" is equal to 1 second.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

One thought on “How to refresh a page in Javascript

Leave a Reply

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