[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

window intervals

Hello,

Is it possible to know the number of active intervals in a window?

Thanks,
Dana
0
Relegence
Asked:
Relegence
2 Solutions
 
Pravin AsarCommented:
When you setInterval, stack them in an array. array.length will give you number of active inetervals.

You need to write your code for managing these.

var myint = new Array();

myint[0] =window.setInterval ("func1()", 1000);
myint[1] =window.setInterval ("func2()", 1000);

alert (myint.length);
0
 
RelegenceAuthor Commented:
I did that but i'm not sure it can help me.
My page can display different types of data. For each type i want to clear the previous set of intervals and create new ones.
I am doing that by saving the intervals names in an array, as suggested, so that after every change of data i clear the previous intervals and create new ones.
Since the performence of the page is not so good, i have a feeling that this mechanism doesn't work so well. To make sure, i thought i would popup an alert with the number of active intervals.
Is that possible?

Thanks you,
Dana
0
 
shaggy_the_sheepCommented:
Hi

if you put all your timers into an array named say... timers()

then to get an alert..

funtion countTimer(){
var msg = ''
for(var x in timers)
   msg = msg + '\n' + timers[x]

alert(msg)
}
<span onclick="countTimer()">Click Me</span>

That shoudl give you an idea of how many timers there are

Richard
0
 
Michel PlungjanIT ExpertCommented:
If the timers are not associative arrays, then
<a href="#" onClick="alert(timers.length); return false">Click</a>
0
 
shaggy_the_sheepCommented:
yep that would do it aswell...a tad easier as well! lol
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now