Solved: refresh page every second javascript

The main problem is that the refresh rate of a page is often set to 60Hz, which means that it will refresh every second. This can be a problem if you are trying to use JavaScript to interact with the page, as it will be constantly polling the page for changes.


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>



How to refresh a page

In JavaScript, you can refresh a page by using the window.refresh() function. This function takes two arguments: the URL of the page to be refreshed and a callback function. The callback function is called when the page has been refreshed.

Related posts:

Leave a Comment