How To Refresh a Page Automatically

Hello Guys Welcome to Coding Gurus Online Portal ...!

When you need your web page to be automatically refreshed for every 5 seconds or any second then, you can use this meta tag. It's a simple code, put it between the head tag on your web page.

You might have seen such pages in many websites and the very best example is your facebook news feed page, i.e. your home page of your facebook account, or your gmail inbox. The page displays the latest feed or update immediately it encounters one. But the fact is that it just keeps refreshing the page every few seconds thus updating the latest feed that comes in.

So here you have a code to make your very own website so very interactive and enterprising.

Using Meta Tag

This script is easy but powerful. Many websites use this script to refresh the same page, for example, my website updates in every 10 minutes and I want to show user my latest content then I put this script to my page and set it refreshs in every 10 minutes.

Code

<head>
<meta http-equiv="refresh" content="2" >
</head>
// content = time in seconds.

Using Javascript

This is another script which refreshes a webpage, after the specified amount of time.Here we use JavaScript to do that, when we could accomplish the same thing using the meta tag also as defined above.

Code

<script>
//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:30"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}
window.onload=beginrefresh
</script>