42

this is my code

<html>
<head>
    <script language="javascript" src="JS/jQuery.js"></script>
    <script>
        function page_refresh(){
            document.getElementById('form2').action="project_file_dir.cfm"  
            document.getElementById('form2').submit();          
        }

    </script>
</head>
<body >
<cfoutput>
<cfset fileLocation ="\\squeaker\SiSystemsFile\WebServices\WebSites\Perforce\Bhargavi"> <!--- On mac set to /tmp --->
<cfdirectory
        action = "list"
        directory = "#fileLocation#"
        name = "files"
        filter="*.*">
<form  method="post" id="form2">
    <cfset f="#files.recordcount#">  
    <cfset mydatetime=now()>
    <cfset a=TimeFormat(MyDateTime,'hh:mm:ss tt')>
      Total File in <b> #fileLocation# </b> Count is <b> #f# </b> #TimeFormat(MyDateTime,'hh:mm tt')#
       <input type="button" name="Refresh" value="refresh" onclick="page_refresh()"><br>
       <b>Next Run</b>
      <cfset b=TimeFormat(DateAdd('n', +5, MyDateTime),'hh:mm:ss tt')>
       #TimeFormat(DateAdd('n', +5, MyDateTime),'hh:mm tt')#
    </cfoutput>

<cfset a= Minute(Now())>
<cfset b=a%5 >  
<cfoutput>#b#</cfoutput>
<!--- <cfinclude template="page_move_2.cfm"> --->
<cfloop condition="b gt 0">
        <cfoutput>inside loop</cfoutput>
    <cfset Sleep(6000)>

    <cfset b = b - 1 >

</cfloop>
<cfoutput>hi</cfoutput>
</form>
</body>
</html>

i need to refresh the page for every 5 mins . how to do this . i used sleep() function but ui itself loaded after that sleep() is executed . this me how to reload the page for every 5 mins

1

4 Answers 4

146

Refresh document every 300 seconds:

Using HTML Meta tag, add this inside the <head> tag of the page:

<meta http-equiv="refresh" content="300">

Using Script:

setInterval(function() {
    window.location.reload();
}, 300_000); // in ms
2
  • 8
    The interval callback only runs once since the reloading stops any scripts from running. setTimeout would achieve the same thing.
    – ekuusela
    Apr 9, 2015 at 6:12
  • current code works in normal and ignores post variables. can we do this with post variables? May 21, 2015 at 5:28
20

Page should be refresh auto using meta tag

<meta http-equiv="Refresh" content="60"> 

content value in seconds.after one minute page should be refresh

4
  • 1
    Honestly this is the simplest answer out there, and doesn't require any javascript Oct 9, 2020 at 22:28
  • 1
    This is the best answer. Is it blocking in any way? It's not js but how the html page counts the content="second"?
    – Marco
    May 3, 2023 at 18:22
  • In HTML and XHTML, one can use the meta element with the value of the http-equiv attribute set to "Refresh" and the value of the content attribute set to "0" (meaning zero seconds), followed by the URI that the browser should request. It is important that the time-out is set to zero, to avoid that content is displayed before the new page is loaded. The page containing the redirect code should only contain information related to the redirect. May 14, 2023 at 5:26
  • This is not restoring the scroll position Sep 29, 2023 at 3:56
15

Install an interval:

<script type="text/javascript">    
    setInterval(page_refresh, 5*60000); //NOTE: period is passed in milliseconds
</script>
0
4

Auto reload with target of your choice. In this case target is _self set to every 5 minutes.

300000 milliseconds = 300 seconds = 5 minutes

as 60000 milliseconds = 60 seconds = 1 minute.

This is how you do it:

<script type="text/javascript">
function load()
{
setTimeout("window.open('http://YourPage.com', '_self');", 300000);
}
</script>
<body onload="load()">

Or this if it is the same page to reload itself:

<script type="text/javascript">
function load()
{
setTimeout("window.open(self.location, '_self');", 300000);
}
</script>
<body onload="load()">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.