如何每5秒重新加载一次页面?

2024-04-24 14:14:32 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

要重新加载同一页,不需要第二个参数。你可以使用:

 <meta http-equiv="refresh" content="30" />

每30秒触发一次重新加载。

对于3秒后的自动重新加载和清除缓存,可以使用javascript setInterval函数轻松完成。下面是简单的代码

&13;
&13;
$(document).ready(function() {
  setInterval(function() {
    cache_clear()
  }, 3000);
});

function cache_clear() {
  window.location.reload(true);
  // window.location.reload(); use this if you do not remove cache
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<p>Auto reload page and clear cache</p>

你也可以用meta

<meta http-equiv="Refresh" content="5">
 <meta http-equiv="refresh" content="5; URL=http://www.yourdomain.com/yoursite.html">

如果必须在脚本中使用setTimeout,例如:

setTimeout(function(){
   window.location.reload(1);
}, 5000);

相关问题 更多 >