473,614 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(i d))?

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=s etTimeout;
var timerSaved=0;
setTimeout = new function(arg,ti me)
{
/*alert('timer: '+arg+', '+time);*/
timerSaved=oldS etTimeout(arg,t ime);
return timerSaved;
}

Greets,
P.
Jul 23 '05 #1
1 6019
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(i d))?
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=s etTimeout;
var timerSaved=0;
setTimeout = new function(arg,ti me)
{
/*alert('timer: '+arg+', '+time);*/
timerSaved=oldS etTimeout(arg,t ime);
return timerSaved;
}


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

var origSetTimeout = window.setTimeo ut;
window.setTimeo ut = function(f, t) {
alert('here');
return origSetTimeout( f, t);
}
var t = setTimeout('tes t()', 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.setTimeo ut = function(f, t) {
if (!window.timerI ds || window.timerIds .constructor != Array) {
window.timerIds = [];
}
window.timerIds .push(origSetTi meout(f, t));
}
setTimeout('tes t()', 2000);
setTimeout('tes t()', 2000);
setTimeout('tes t()', 2000);
alert(window.ti merIds.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*****@agrico reunited.com>
comp.lang.javas cript 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
2710
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
2263
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 url http://godot.urol.uic.edu/output.html
1
6251
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 under lynx and elinks, but some doesn't. Is there any converter from javascript to HTML or PHP or PERL? Is there any ASCII web browser that fully supports Javascript. Thanks
1
3184
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 gmail use to detect and warn "Gmail says my browser's cache is full" http://gmail.google.com/support/bin/answer.py?answer=14106 then there should be a way to do it if google can do it. Any thoughts ?
13
8602
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 excel file but I don't know how to use ADO to work with it's contents. So far I have the following code that works: <html> <script> window.onload = function () {
6
2917
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 HTML is *not* visible in the source view.
1
1267
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
1399
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 list different HTML is displayed somewhere else on the page. I know this might be possible by adding a submit button and reloading the page. But is there a way to do it without the submit button? I know that Java might be able to accomplish...
10
1617
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.... The result of the main html showed blank. Any idea? Thanks and Best Rgds, Andrew
0
8180
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8130
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8623
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8429
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7091
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4050
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4121
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1423
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.