定时自动刷新浏览器中的 HTML 页面 - 每 15 分钟
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7206694/
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
Refresh HTML Page in Browser Automatically on Timer - Every 15 Min
提问by Drew
Is it possible to automatically refresh a website on a timer, like every 15 minutes? Basically, we will be making updates to a website and we want it to automatically refresh so it will show up on a big monitor we have which is controlled from a different computer.
是否可以在计时器上自动刷新网站,例如每 15 分钟一次?基本上,我们将对网站进行更新,我们希望它自动刷新,以便它显示在我们拥有的由另一台计算机控制的大显示器上。
So instead of going to that other computer to click refresh when changes are made, it would just automatically refresh so we can keep it up there.
因此,与其在进行更改时去另一台计算机单击刷新,它只会自动刷新,以便我们可以将其保留在那里。
Thanks!
谢谢!
回答by ckittel
Place this inside <head>
to refresh page after 900 seconds:
将它放在里面<head>
以在 900 秒后刷新页面:
<meta http-equiv="refresh" content="900"> <!-- Refresh every 15 minutes -->
For what it's worth, the w3c has officially deprecated this feature, but browsers continue to support this feature. For your purposes, this is an ideal solution. It's just not a recommended solution for "public" (www)-facing web sites any more.
就其价值而言,w3c 已正式弃用此功能,但浏览器继续支持此功能。对于您的目的,这是一个理想的解决方案。它不再是面向“公共”(www)的网站的推荐解决方案。
回答by box86rowh
You dont even need js to do this! Look at the refresh meta tag: http://webdesign.about.com/od/metataglibraries/a/aa080300a.htmYou can use this to refresh the page on any interval.
你甚至不需要js来做到这一点!查看刷新元标记:http: //webdesign.about.com/od/metataglibraries/a/aa080300a.htm您可以使用它在任何时间间隔刷新页面。
回答by www139
window.setTimeout(function(){
//refresh the page after 900,000 miliseconds (15 minutes)
//reload the page (javascript has many ways of doing this)
location.reload();
},900000);
That should help.
那应该有帮助。
回答by jasoares
Although the refresh meta tag is the simpler solution to update information on a webpage it is also a pretty old and dated solution.
虽然刷新元标记是更新网页信息的更简单的解决方案,但它也是一个相当古老和过时的解决方案。
Imagine for example that Google maps would need to refresh the whole page when you pan the map view. There is where ajax comes in, you can find a lot information about it online like thisfor example.
想象一下,例如,当您平移地图视图时,Google 地图需要刷新整个页面。还有就是AJAX进来,你可以在网上找到关于它的很多信息,像这样的例子。
I don't know specifically what was your intention but just wanted to give this background information, if just a refresh is really what you need then the answers from box86rowhand ckittelis all you need.
我不知道你的具体意图是什么,但只是想提供这些背景信息,如果你真的需要刷新,那么box86rowh和ckittel的答案就是你所需要的。
回答by tree
Pass the url in the querystring, and then just load it in a frame
在查询字符串中传递 url,然后将其加载到框架中
source: javascriptkit.com
来源:javascriptkit.com
<script>
<!--
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()",200)
}
}
window.onload = beginrefresh
//-->
</script>
</head>
<body>
<iframe src="" id="refreshResults" frameborder="0" width="1800" height="1800"></iframe>
<script>
var http = new XMLHttpRequest();
$(function(){
$("#refreshResults").attr('src','<%=Request.Querystring("w")%>');
});
</script>