473,788 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

detect listeners

Hello,

Is there a way (in JS) to detect listeners on an element and identify
them? The purpose would be to selectively attach additional listeners
if certain conditions are met. For example, I want to attach
listenerA to links that go to PDFs and listenerB to links that go off
site. But, I don't want both A and B attached to offsite links that
point to PDFs.

I would like to be able to choose which to attach, so that
if (! ele has listenerA) attach listenerB. Or vice versa.

I have looked through my reference materials and googled but I don't
see anything that seems to answer this question.

Thanks.

mp
--
Michael Powe mi*****@trollop e.org Naugatuck CT USA
"...we built a new continent in cyberspace where we could go live and be
free. And the nice thing is that, because we built it, we didn't have
to steal it from aboriginal peoples. It was completely empty, and we
invite everyone to live there with us. No immigration restrictions.
There's room for everyone in the world. Come live in the free world
and be free. That's our idea." -- Richard Stallman
Jan 28 '06 #1
2 1727
On 2006-01-28, Michael Powe <mi**********@t rollope.org> wrote:
Hello,

Is there a way (in JS) to detect listeners on an element and identify
them? The purpose would be to selectively attach additional listeners
if certain conditions are met. For example, I want to attach
listenerA to links that go to PDFs and listenerB to links that go off
site. But, I don't want both A and B attached to offsite links that
point to PDFs.

I would like to be able to choose which to attach, so that
if (! ele has listenerA) attach listenerB. Or vice versa.

I have looked through my reference materials and googled but I don't
see anything that seems to answer this question.


listeners attached using HTML are anonymous functions in mozilla you can use
the .toSource method of the appropriate domObject.oneve nt to find their
content. myDiv.onclick.t osource()

Listners attached using domObject.onEve nt=functionName ;
are functions can be identified using ==

if( myDiv.onclick == functionName ) ...

Bye.
Jasen
Jan 29 '06 #2
Michael Powe wrote:

Is there a way (in JS) to detect listeners on an element and identify
them?


For those listeners added as attributes in the markup (e.g.
<input onclick="alert( event.type);" type="button" value="test">
) the element object has a property named oneventname (e.g.
inputObject.onc lick
) which is a function object (e.g.
if (typeof inputObject.onc lick == 'function')
)
For listeners added with W3C DOM Level 2 addEventListene r there is no
way to detect those listeners, you are supposed to keep track of that
yourself in your code.

DOM Level 3 adds a method hasEventListene rNS
<http://www.w3.org/TR/DOM-Level-3-Events/events.html#Eve nts3-hasEventListene rNS>
but that is not a W3C recommendation, only a note. I don't know any
browser implementing that.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 29 '06 #3

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

Similar topics

4
3013
by: Hal Vaughan | last post by:
I've said here before that I'm self taught. I have 4 reference books, and they mention listeners and give partial examples, but not one gives me a good, clear example of setting up a listener, using it, and disposing it. Can anyone either point me to some good examples online, or show me one? It would save me a day or two of try different ways to do it. Thanks for any help. Hal
3
2659
by: Rich Wahl | last post by:
I am writing a personal application that uses windowListeners, ActionListeners and possible ItemListeners (combo boxes). I have one of the Buttons (ActionListeners) set to have a popup frame/panel to display a Choice. But I would like the Program to not continue on until the user makes their selection from the dropdown/Combo box in the new popup window. Right now, I have it setup so that the Listeners for the main frame are looking...
1
1856
by: Fred Mellender | last post by:
When I code: Debug.Assert(false, "this is a message"); it works fine, and out comes the dialog box. When I code Trace.Listeners.Clear(); Debug.Assert(false, "this is a message"); No message is output. In the debugger I see that clearing the Trace Listeners clears the Debug
3
1417
by: Steph | last post by:
hello, i m looking for detect the runmode (console, aspx, etc) and adapt my class (delegate) for output writting... thx mcf
3
1548
by: Absolon | last post by:
Hi, Can anyone tell the advantages/dis-advantages of adding a listener to the listeners collection? In MSDN it says that listeners not in the collection do not recieve all trace output. What will be missing? -- Rgds,
6
3959
by: Zytan | last post by:
According to http://www.15seconds.com/issue/020910.htm I am doing this in the c'tor of a 'logfile' class: objStream = new System.IO.FileStream(logFilename, System.IO.FileMode.OpenOrCreate); objTraceListener = new TextWriterTraceListener(objStream); Trace.Listeners.Add(objTraceListener); So, now all Debug.Write and Trace.Write get logged to the file. In the d'tor I am doing:
12
6237
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
0
5014
by: kronus | last post by:
Hi everyone, Yes, I need to use you guys as a sounding board once more :-) I have a button that has two listeners one for mouse up and the other for mouse down and they point to the same function. $btnRewind.addEventListener(MouseEvent.MOUSE_DOWN,onBtnBack); $btnRewind.addEventListener(MouseEvent.MOUSE_UP,onBtnBack);
0
9656
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
10366
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...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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
8993
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...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.