65.9K
CodeProject is changing. Read more.
Home

Automatically refresh page after some interval

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 20, 2011

CPOL
viewsIcon

16803

DescriptionR...

Description

Refresh page using JavaScript.

Code

<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.