已解决:每秒刷新一次页面 javascript

主要问题是一个页面的刷新率经常设置为60Hz,也就是说每秒刷新一次。 如果您尝试使用 JavaScript 与页面交互,这可能会成为一个问题,因为它会不断轮询页面以进行更改。

I want to refresh a page every second. I have tried this code but it doesn't work:
<code>&lt;script type="text/javascript"&gt;
    setTimeout("location.reload(true);",1000);
&lt;/script&gt;
</code>


A:

You can use <code>setInterval()</code>:


<code>setInterval(function() {
  console.log('refreshed');
}, 1000);</code>



如何刷新页面

在 JavaScript 中,您可以使用 window.refresh() 函数刷新页面。 此函数有两个参数:要刷新的页面的 URL 和一个回调函数。 刷新页面时调用回调函数。

相关文章:

发表评论