All TalkersCode Topics

Follow TalkersCode On Social Media

JavaScript Refresh Page Every Minute

Last Updated : Jan 1, 2023

JavaScript Refresh Page Every Minute

In this tutorial we will show you the solution of JavaScript refresh page every minute, we can set any minute, seconds or time using javascript inbuilt methods, here we used reload() and setTimeout() methods.

Using these methods we easily reloaded our webpage for every minute. First we need to set timer for every minute then within function we will reloaded our page.

For those access we need window object service then only both method will work properly.

Step By Step Guide On JavaScript Refresh Page Every Minute :-

Here we defined methods setTimeout() and reload(). The global setTimeout() method sts a timer which executes a function or specified piece of code once the timer expires.

We use this to delay some kind of executions and also used for animations or DOM manipulations in jquery.

The reload() method is used to reload a webpage. It is similar to refresh button of the browser. This method does not return any value.

<!DOCTYPE html>
        <title>Auto Refresh Page Every Minute</title>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contains information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  5. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  6. Within <script> tag we defined our javascript program, here first we called setTimeout() method with ‘window’ object because we used on browser window so we need to specify it and the value ‘60000’ refers ‘one minute or 60seconds’.
  7. After 60seconds within ‘setTimeout()’ what we defines it will work and within that we defined reload() method with services of ‘window.location’.So the current location of window will automatically reloaded for each 60seconds.
  8. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion we are able to know how to refresh page for every minutes.

When we execute our program on browser we can see one text we defined using h1 tag and that page will automatically reload for each minutes.

Here we sets ‘60sec’ so it will reloaded each minute if you need to set any other timing value you can modify and use this program.

We can also do this by another type using ‘meta’ tag with attribute ‘content’ we can set timer and attribute need to set as ‘http-enquiv’ value to ‘refresh’.

We will see about them in future. I hope this tutorial on JavaScript refresh page every minute helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials