Javascript页面自动刷新 [英] Javascript page auto refresh
本文介绍了Javascript页面自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜。可以帮上我这个javascript代码正确
hi. can sme on please help me to make this javascript code correct
<script type="text/javascript">
setTimeout('window.location.href=window.location.href;', 300000);
</script>
此代码将自动刷新页面300000毫秒,即5分钟。
所以我的页面包含如下所示
this code will refresh the page automatically in 300000 milliseconds which is 5 mins.
so my page contains like this below
<script type="text/javascript">
setTimeout('window.location.href=window.location.href;', 1080000);
</script>
<div id="norefresh">page refresh in 5 mins click "HERE" to not refresh</div>
所以我想在剩下1分钟时刷新id norefresh中的文本必须显示为取消页面刷新。谢谢。
so i want to make it when like 1 min left to refresh that text in id norefresh must be showing like that to cancel page refresh. thank you.
推荐答案
请看我对这个问题的评论。请在此处查看使用setTimeout
的说明:
http://stackoverflow.com/questions/4644027/how-to-automatically-reload-a-page-after- a-given-period-of-inactivity [ ^ ]。
(只是忽略不活动时期的方面并显示鼠标/键盘绑定代码。)
完整的答案取决于刷新的目的;一般情况下,还有其他方法。通常,自动刷新是为了实现 pull技术,这是一件坏事,是由于缺少服务器推送。
请参阅我过去的答案和下面引用的文章:
http:// en。 wikipedia.org/wiki/Pull_technology [ ^ ],
http://en.wikipedia.org/wiki/Server-push [ ^ ],
网站帐户的应用程序仪表板 [ ^ ]。
-SA
Please see my comment to the question. Please see the explanation of the use ofsetTimeout
here:
http://stackoverflow.com/questions/4644027/how-to-automatically-reload-a-page-after-a-given-period-of-inactivity[^].
(Just ignore the aspect of "period of inactivity" and the mouse/keyboard binding code shown.)
The full answer depends on the purpose of your refresh; in general case, there are other methods. Typically, auto refresh is done to implement pull technology, which is a bad thing, a result of the lack of server push.
See my past answer and the article referenced below:
http://en.wikipedia.org/wiki/Pull_technology[^],
http://en.wikipedia.org/wiki/Server-push[^],
Application 'dashboard' for website accounts[^].
—SA
这篇关于Javascript页面自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文