Clear Included setInterval?

I have a javascript file included, which has this:

setInterval(adfunction, 38000);

I like it on all pages, but one. Was seeing if a way to clear that setinterval inline on that one page.

Possible?

Cheers!
Ryan

You’d need the ID of that interval to do that. These IDs are just whole numbers incrementing from zero though, so if you start another interval you would be able to clear all running intervals (and timeouts, which share the same ID pool)…

const id = setTimeout(() => {})

for (let i = 0; i <= id; i++) {
  clearInterval(i)
}

Of course, if this is a good idea is another question… I suppose your best bet would be not to include that script in the first place. ^^

1 Like

Assign that interval to a function, and you can then easily clear it later on.

var adInterval = setInterval(adfunction, 38000);

and when you want to remove that from the one page:

clearInterval(adInterval);
1 Like

Thanks guys. I ended up applying a variable to the interval, and doing a clearInterval on the variable. Worked like a charm.

He, seems I entirely misunderstood your question. :-P

lol.

I had an idea that the variable was a solution, was just being lazy to avoid editing the source JS file and instead try strictly inline.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.