Automatically Refresh HTML page or div after some Interval

Automatically Refresh HTML page or div after some Interval

In this post we will give you information about Automatically Refresh HTML page or div after some Interval. Hear we will give you detail about Automatically Refresh HTML page or div after some IntervalAnd how to use it also give you demo for it if it is necessary.

In this post, I will let you know how to refresh HTML page after some time interval automatically.

There are so many ways to refresh page after defined time interval.

You can use the JavaScript function location.reload() to refresh active page.


Example 1: Reload page using JavaScrip setTimeout Method

  1. <!DOCTYPEhtml>
  2. <html>
  3. <head>
  4.     <title>Reload page after 5 seconds</title>
  5. <script>
  6. setTimeout(function(){
  7. location.reload();
  8. },5000); // 5000 milliseconds means 5 seconds.
  9. </script>
  10. </head>
  11. <body>
  12. <h1>Welcome to Expert PHP !</h1>
  13. </body>
  14. </html>
<!DOCTYPE html>
<html>
<head>
	<title>Reload page after 5 seconds</title>
    <script>
       setTimeout(function(){
           location.reload();
       },5000); // 5000 milliseconds means 5 seconds.
    </script>
</head>
<body>
<h1>Welcome to Expert PHP !</h1>
</body>
</html>

Above script will refresh your HTML page after every 5 seconds.

setTimeout() method is used to set a timer which executes a method or specified piece of code after a specified number of milliseconds.


Hint:

1000 ms = 1 second.


Example 2 : Reload page using JavaScrip setInterval Method

  1. <!DOCTYPEhtml>
  2. <html>
  3. <head>
  4.     <title>Reload page after 5 seconds</title>
  5. <script>
  6.     function autoRefresh()
  7.     {
  8.         window.location = window.location.href;
  9.     }
  10.      setInterval('autoRefresh()', 5000);
  11.     </script>
  12. </head>
  13. <body>
  14. <h1>Welcome to Expert PHP !</h1>
  15. </body>
  16. </html>
<!DOCTYPE html>
<html>
<head>
	<title>Reload page after 5 seconds</title>
    <script>
	function autoRefresh()
	{
		window.location = window.location.href;
	}
	 setInterval('autoRefresh()', 5000);
	</script>
</head>
<body>
<h1>Welcome to Expert PHP !</h1>
</body>
</html>

setInterval() method is used to call the function continuously until clearInterval() is called.


Example 3 : Reload page using meta tag in head tag

  1. <!DOCTYPEhtml>
  2. <html>
  3. <head>
  4.     <title>Reload page after 5 seconds</title>
  5. <metahttp-equiv="refresh"content="5"/>
  6. </head>
  7. <body>
  8. <h1>Welcome to Expert PHP !</h1>
  9. </body>
  10. </html>
<!DOCTYPE html>
<html>
<head>
	<title>Reload page after 5 seconds</title>
    <meta http-equiv="refresh" content="5" />
</head>
<body>
<h1>Welcome to Expert PHP !</h1>
</body>
</html>

http-equiv="refresh" will refresh automatically and a content parameter giving the time interval in seconds.


Try this code and feel free to give you suggestion.

Label :

HTML

How To

Web Development

Hope this code and post will helped you for implement Automatically Refresh HTML page or div after some Interval. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

67  +    =  68

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US