Click here to Skip to main content
15,884,388 members
Articles / Web Development / HTML
Alternative
Tip/Trick

Automatically refresh page after some interval

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
20 Jun 2011CPOL 16.3K   1  
DescriptionR...

Description


Refresh page using JavaScript.


Code


XML
<html>
<head>
<title>Refresh page using Javascript</title>
<script type="text/JavaScript">
	function RefreshPage(Period) 
	{
		setTimeout("location.reload(true);", Period);
	}
/* Optional code */
	var Today = new Date();
	var day = Today.getDate();
	var month = Today.getMonth();
	var year = Today.getFullYear();
	var hours = Today.getHours();
	var minutes = Today.getMinutes();
	var seconds = Today.getSeconds();
	document.write(day + "/" + month + "/" + year + " " + hours + ":" + minutes + ":" + seconds)
/* End of Optional code */
</script>
</head>
<body  önload="javaScript:RefreshPage(1000);">
</body>
</html>

Browser Compatibility


I have tested this script in the following Web browsers:



  • Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Safari
  • Opera

Output


20/5/2011 17:56:51

You can see the running date-time of today on page refresh. Here I gave 1000 milliseconds (1 sec) in the code (for page refresh) and you can change the value based on your requirement.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --