javascript 每 5 分钟自动刷新一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19807665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
auto refresh for every 5 mins
提问by Bhargavi
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
我需要每 5 分钟刷新一次页面。这个怎么做 。我使用了 sleep() 函数,但在执行 sleep() 之后加载了 ui 本身。这是我如何每 5 分钟重新加载一次页面
回答by Krish R
Refresh document every 300 seconds using HTML Meta tag add this inside the head tag of the page
使用 HTML Meta 标记每 300 秒刷新一次文档,将此添加到页面的 head 标记中
<meta http-equiv="refresh" content="300">
Using Script:
使用脚本:
setInterval(function() {
window.location.reload();
}, 300000);
回答by Claudix
Install an interval:
安装间隔:
<script type="text/javascript">
setInterval(page_refresh, 5*60000); //NOTE: period is passed in milliseconds
</script>
回答by Kaushik shrimali
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
以秒为单位的内容值。一分钟后页面应刷新
回答by SeekLoad
Auto reload with target of your choice. In this case target is _self
set to every 5 minutes.
自动重新加载您选择的目标。在这种情况下,目标_self
设置为每 5 分钟一次。
300000 milliseconds = 300 seconds = 5 minutes
300000 毫秒 = 300 秒 = 5 分钟
as 60000 milliseconds = 60 seconds = 1 minute.
如60000 毫秒 = 60 秒 = 1 分钟。
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()">