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
- <!DOCTYPEhtml>
- <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>
<!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
- <!DOCTYPEhtml>
- <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>
<!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
- <!DOCTYPEhtml>
- <html>
- <head>
- <title>Reload page after 5 seconds</title>
- <metahttp-equiv="refresh"content="5"/>
- </head>
- <body>
- <h1>Welcome to Expert PHP !</h1>
- </body>
- </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.
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