Javascript Auto Refresh Current Page with Regular Intervals

Reading Time: 3 minutes
665 Views

Inside this article we will see the concept i.e Javascript Auto Refresh Current Page with Regular Intervals Example Tutorial. Article contains the classified information about How to Auto Refresh Page Every 10 Seconds using Javascript.

If you are looking for a solution i.e Refresh a Web Page in JavaScript in regular intervals then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.

Read More: How To Capitalize The First Letter of String In JavaScript

Let’s get started.

Application Programming

Create a folder say page-reload in your localhost directory. Create a file index.html into it.

Auto page reload in a specific Time (Single time only)

<!doctype html>
  
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Javascript Auto Refresh Current Page with Regular Intervals</title>
  </head>
  <body>

    <h3>Automatically Refresh or Reload a Page using Javascript</h3>

    <script>

	   setTimeout(function(){

	       location.reload();

	   },3000); // 3000 milliseconds means 3 seconds.

   </script>

  </body>

</html>

Concept

Reload page itself in a specific time period.

setTimeout(function(){

   location.reload(); // Reload page itself

},3000); // 3000 milliseconds means 3 seconds.

Auto page reload in regular intervals (Regular reload)

Read More: How To Generate And Download CSV File in Javascript Tutorial

Open index.html file and write this code for it.

<!doctype html>
  
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Javascript Auto Refresh Current Page with Regular Intervals</title>
  </head>
  <body>

    <h3>Automatically Refresh or Reload a Page using Javascript</h3>

    <script>

	   setInterval(function(){

	       location.reload();

	   },3000); // 3000 milliseconds means 3 seconds.

   </script>

  </body>

</html>

Concept

After every 3 seconds, page itself get reload every time.

setInterval(function(){
    
     location.reload();

},3000); // 3000 milliseconds means 3 seconds.

Application Testing

Open browser and type your application URL:

URL: http://localhost/page-reload/index.html

We hope this article helped you to learn Javascript Auto Refresh Current Page with Regular Intervals in a very detailed way.

Read More: JavaScript How To Call a Function Repeatedly Every 5 Seconds

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more