Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 513157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:23:37+00:00 2026-05-13T07:23:37+00:00

The window.setTimeout (and related setInterval) function in Javascript allows you to schedule a function

  • 0

The window.setTimeout (and related setInterval) function in Javascript allows you to schedule a function to be executed sometime in the future:

id = setTimeout(function, delay);

where “delay” is the number of milliseconds into the future at which you want to have the function called. Before this time elapses, you can cancel the timer using:

clearTimeout(id);

What I want is to update the timer. I want to be able to advance or retard a timer so that the function gets called x milliseconds sooner or later than originally scheduled.

If there were a getTimeout method, you could do something like:

originally_scheduled_time = getTimeout(id);
updateTimeout(id, originally_schedule_time + new_delay);  // change the time

but as far as I can tell there’s nothing like getTimeout or any way to update an existing timer.

Is there a way to access the list of scheduled alarms and modify them?

Is there a better approach?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:23:37+00:00Added an answer on May 13, 2026 at 7:23 am

    If you really want this sort of functionality, you’re going to need to write it yourself.

    You could create a wrapper for the setTimeout call, that will return an object you can use to “postpone” the timer:

    function setAdvancedTimer(f, delay) {
      var obj = {
        firetime: delay + (+new Date()), // the extra + turns the date into an int 
        called: false,
        canceled: false,
        callback: f
      }; 
      // this function will set obj.called, and then call the function whenever
      // the timeout eventually fires.
      var callfunc = function() { obj.called = true; f(); }; 
      // calling .extend(1000) will add 1000ms to the time and reset the timeout.
      // also, calling .extend(-1000) will remove 1000ms, setting timer to 0ms if needed
      obj.extend = function(ms) {
        // break early if it already fired
        if (obj.called || obj.canceled) return false; 
        // clear old timer, calculate new timer
        clearTimeout(obj.timeout);
        obj.firetime += ms;
        var newDelay = obj.firetime - new Date(); // figure out new ms
        if (newDelay < 0) newDelay = 0;
        obj.timeout = setTimeout(callfunc, newDelay);
        return obj;
      };
      // Cancel the timer...  
      obj.cancel = function() {
        obj.canceled = true;
        clearTimeout(obj.timeout);
      };
      // call the initial timer...
      obj.timeout = setTimeout(callfunc, delay);
      // return our object with the helper functions....
      return obj;
    }
    
    var d = +new Date();
    var timer = setAdvancedTimer(function() { alert('test'+ (+new Date() - d)); }, 1000);
    
    timer.extend(1000);
    // should alert about 2000ms later
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In javascript there's this sweet, sweet function window.setTimeout( func, 1000 ) ; which will
I'm doing an animation using javascript: function animate(){ window.setTimeout(function(){ //Do a new frame and
function a(delay){ this.randomVal = Math.random(); window.setTimeout(function(){ document.write('function a called - '+this.randomVal+' '+delay+'<br/>'); }, delay)
function runAgain() { window.setTimeout(foo, 100); } function foo() { //Do somthing runAgain(); } I
I want to run a function in TruClient (Firefox) every 0.1 seconds using window.setTimeout:
When I pass 'this' to an anonymous function like so: MyClass.prototype.trigger = function(){ window.setTimeout(function(){this.onTimeout();},1000);
Window.open javascript function is not working in Mozilla, but working in other browsers, here
I have the following: window.setTimeout(function() { window.location.href = 'file.php'; }, 115000); How can I,
The following script produces Hello, undefined, Hello message boxes: function action(callback) { window.setTimeout(callback, 1000);
function myfunction() { window.setTimeout(alert('I waited for you.'),700000000); } I call a function like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.