window intervals

Posted on 2006-05-25
Last Modified: 2010-10-05

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

Question by:Relegence
    LVL 28

    Expert Comment

    by:Pravin Asar
    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);

    Author Comment

    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,
    LVL 5

    Accepted Solution


    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]

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

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

    LVL 75

    Assisted Solution

    by:Michel Plungjan
    If the timers are not associative arrays, then
    <a href="#" onClick="alert(timers.length); return false">Click</a>
    LVL 5

    Expert Comment

    yep that would do it aswell...a tad easier as well! lol

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now