How to reload page based on number of seconds
In case in any page if you want to reload the page for every 5 sec. then use this simple code to reload the page in different way.
The reloading page can be done in many ways like html, javascript and PHP
In HTML
As basic in html page itself you can change meta data to reload the page in some seconds
The following example shows
Ex-1:
//<meta http-equiv="Refresh" content="5">
Waits for 5 seconds to reload the page
Ex-2:
//<meta http-equiv="Refresh" content="10;url=index.html"
Waits for 10 seconds to reload the page and redirect the page to index.html
In PHP
From php page reload of page can be done in this way
Ex:
$page = $_SERVER['PHP_SELF'];
$sec = "5";
header("Refresh: $sec; url=$page");
?>
Here the $page can give you the current page information and the $sec gives you the seconds for how long the page should waitsIn JAVASCRIPT
The same reloading can be done in javascript with the following code
Ex:
Here the javascript will be define with the functionfunction Re_load() {window.location ='http://index.php'
And the calling this javascript function onload of the body inside
//onload="timer=setTimeout(‘Re_load ()',3000)"
So after 3000 milisec the page will reload automatically
No comments:
Post a Comment