473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

List Running Timers in JavaScript (provided in html dom?)

Hello,

Does anybody know a way to retreive the running timers (their ids) in a html
page?
I cannot find something in the html dom at first sight.
Is there collection of timers available (like window.all[], forms[],
frames[] and such)?
Some other way?

When you create a timer (setTimeout), the return value is the timer id.
Suppose that some script (which you do not own and cannot change) calls
setTimeout but doesn't store the id.
How to retreive it, to stop the timer (clearTimeout(id))?

I though to override the "setTimeout" like below, but that doesn't work.
Probably since the original setTimeout is used before I declare this new
one.

var oldSetTimeout=setTimeout;
var timerSaved=0;
setTimeout = new function(arg,time)
{
/*alert('timer: '+arg+', '+time);*/
timerSaved=oldSetTimeout(arg,time);
return timerSaved;
}

Greets,
P.
Jul 23 '05 #1
1 6000
Antoine wrote:
Hello,

Does anybody know a way to retreive the running timers (their ids) in a html
page?
I cannot find something in the html dom at first sight.
Is there collection of timers available (like window.all[], forms[],
frames[] and such)?
Some other way?
No, there is no global collection of timer ids.
When you create a timer (setTimeout), the return value is the timer id.
Suppose that some script (which you do not own and cannot change) calls
setTimeout but doesn't store the id.
How to retreive it, to stop the timer (clearTimeout(id))?
You don't. If you don't have a handle (id) for the setTimeout() setInterval()
you can't stop it.
I though to override the "setTimeout" like below, but that doesn't work.
Probably since the original setTimeout is used before I declare this new
one.

var oldSetTimeout=setTimeout;
var timerSaved=0;
setTimeout = new function(arg,time)
{
/*alert('timer: '+arg+', '+time);*/
timerSaved=oldSetTimeout(arg,time);
return timerSaved;
}


It will work if you drop the "new" keyword:

var origSetTimeout = window.setTimeout;
window.setTimeout = function(f, t) {
alert('here');
return origSetTimeout(f, t);
}
var t = setTimeout('test()', 2000);
alert(t);
function test() { var x = 1; }

But I'm not sure what you hope to gain from this. You are saying that the
original script does not store the return value from setTimeout(). If that is
the case, overriding setTimeout() to return the value is useless (since it never
gets stored by the original script). Perhaps what you want to do is store the
timer id in a global collection for later retrieval by your own script:

window.setTimeout = function(f, t) {
if (!window.timerIds || window.timerIds.constructor != Array) {
window.timerIds = [];
}
window.timerIds.push(origSetTimeout(f, t));
}
setTimeout('test()', 2000);
setTimeout('test()', 2000);
setTimeout('test()', 2000);
alert(window.timerIds.join(';'));
function test() { var x = 1; }

You'll want to override clearTimeout() as well, to remove the Array element when
it's been cleared... probably. I don't know exactly what you're hoping to
achieve manipulating timers with script on a page that you can't change the
original script on.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: quikquic | last post by:
Suppose I download a html file with javascript in it, for example, <html> <body> <script language="JavaScript"> document.write("Hello"); </script> </body> </html>
6
by: Gaurav | last post by:
Hello, i have some java script with in html. It runs fine on IE 6.0 but doesnt run on some browsers like IE 5.0. Can someone tell me whats the problem ? And how can i solve it. here is the...
1
by: oleg_orel | last post by:
I need to access web sites using my scripts written in Perl. I use lynx and elinks to access web pages. It works fine, unless the pages has some Javascript code. Most Javascript stuff is working...
1
by: onewebclick | last post by:
Is there a way to detect a browser cache is full using javascript or HTML thorugh a web page and inform the user to clear the cache to improve performance of the website. It looks like google's...
13
by: UnaCoder | last post by:
Hi, I'm trying to use client side JavaScript from an HTML file to open and make changes to an Excel SpreadSheet using ADO w/ ODBC. What a pain it is to do this. Anyways, I am able to open the...
6
by: dark.peony | last post by:
Hi, (--1--) I'm trying to find a way to jump to a link (<a href="ref"></a>) in a page that is generated with javascript. The source view of the page only shows the javascript methods. The...
1
by: Khai Doan | last post by:
Perl has a concept of list / scalar context. Is there such a list context in javascript ? Thanks Khai
10
by: chadsspameateremail | last post by:
I first should list my background and that is that I'm new to PHP. I would like to be able to have an HTML form where there is a list that you choose from. Depending on what item is chosen in the...
10
by: happyse27 | last post by:
Hi all, I have enabled Javascripting in internet explorer 7, and I have been writing script in perl. The thing I cant do now is to pop up image in small html frame from main html page.......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.