Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing window.location.reload Time

Running

`

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

`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This gives me a refresh every 30 seconds. I want to change or pause it while user is typing into a text box.
Thinking a oninput event. How can I change the 30000?

>Solution :

One way to change the refresh interval while the user is typing in a text box would be to use the clearTimeout() function to cancel the existing timeout when the user starts typing, and then use setTimeout() again to set a new timeout when the user stops typing.

Here is an example of how you could do this:

// Set initial refresh interval
var refreshInterval = 30000; // 30 seconds

// Set initial timeout
var timeout = setTimeout(function() {
  window.location.reload(1);
}, refreshInterval);

// Add event listener for the text box
document.getElementById('text-box').addEventListener('input', function() {
  // Clear existing timeout when user starts typing
  clearTimeout(timeout);

  // Set new timeout when user stops typing
  timeout = setTimeout(function() {
    window.location.reload(1);
  }, refreshInterval);
});

In this example, the refreshInterval variable is used to specify the refresh interval. This allows you to easily change the refresh interval without having to modify the setTimeout() call.

When the user starts typing in the text box, the clearTimeout() function is used to cancel the existing timeout. When the user stops typing, a new timeout is set using setTimeout(). This way, the page will only refresh when the user has stopped typing for the specified interval.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading