f



Change delay in timeout

Is there a way to change the delay of an unreferenced settimeout before 
the initial delay has triggered? (I suspect not - at the moment I'm 
having trouble even identifying the settimeout.)

The 3rd party generated code I'm working on incorrectly sets the length 
of the delay.

Andrew Poulos
0
Andrew
12/22/2016 12:41:20 AM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

2 Replies
640 Views

Similar Articles

[PageSpeed] 37

On Wednesday, December 21, 2016 at 6:41:29 PM UTC-6, Andrew Poulos wrote:
> Is there a way to change the delay of an unreferenced settimeout before 
> the initial delay has triggered? (I suspect not - at the moment I'm 
> having trouble even identifying the settimeout.)
> 
> The 3rd party generated code I'm working on incorrectly sets the length 
> of the delay.


setTimeout returns an identifier that can be used to stop it. After stopping it, you could create another with the proper timing:

<https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout>
<https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearTimeout>


If you do not have the id, another possible approach would be to override setTimeout and intercept the call. Off-The-Cuff"

//Your override

var setTimeout = (function(winTimeout){
  return function(fn,delay) {
    return winTimeout(fn, delay * 10)
  }
})(window.setTimeout)

// 3rd Party injected code later

function sayHello(){ alert("Hello") }

function secretSquirrel(){
   setTimeout(sayHello,500)
}

secretSquirrel()


0
Michael
12/22/2016 2:59:03 AM
On 22/12/2016 1:59 PM, Michael Haufe (TNO) wrote:
> On Wednesday, December 21, 2016 at 6:41:29 PM UTC-6, Andrew Poulos
> wrote:
>> Is there a way to change the delay of an unreferenced settimeout
>> before the initial delay has triggered? (I suspect not - at the
>> moment I'm having trouble even identifying the settimeout.)
>>
>> The 3rd party generated code I'm working on incorrectly sets the
>> length of the delay.

> If you do not have the id, another possible approach would be to
> override setTimeout and intercept the call. Off-The-Cuff"
>
> //Your override
>
> var setTimeout = (function(winTimeout){ return function(fn,delay) {
> return winTimeout(fn, delay * 10) } })(window.setTimeout)
>
> // 3rd Party injected code later
>
> function sayHello(){ alert("Hello") }
>
> function secretSquirrel(){ setTimeout(sayHello,500) }
>
> secretSquirrel()

I've allowed the delay in the 3rd party code to be set to 123000 to the 
settimeouts I need to "correct" so by using your code I check for a 
delay of 123000 and correct it accordingly. Thanks.

Andrew Poulos
0
Andrew
12/22/2016 8:23:10 AM
Reply: