473,837 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to discover if attachEvent was done to an element

Max
Hi All,

I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any
way to do this???
Thanks,
Max

Aug 28 '07 #1
12 3775
On Aug 28, 4:37 pm, Max <krya...@yahoo. comwrote:
Hi All,

I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any
way to do this???

Thanks,
Max
Do you need to be notified exactly *when* attachEvent was used? Or do
you come along later and inspect the element to see if it had had an
event listener attached at some point in the past?

Also, for this an other reasons, I don't particularly care to use IE's
proprietary attachEvent at all. Though some would eviscerate me for
saying this, try using the YAHOO! UI library (http://
developer.yahoo .com/yui/) to wrap the browser differences. Your life
will be MUCH easier: YAHOO exposes YAHOO.util.Even t.getListeners, a
method that returns all (YAHOO-library) attached listeners on an
element.

-David

Aug 29 '07 #2
Max wrote:
I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any way to do this???
(Your Question Mark key is borken.)

I don't know any. But, since attachEvent() is IE-proprietary, you could
equally use the `onclick' property, which value you can test against.
Your code would still be proprietary, but would at least support more DOMs
(including NN4, Geckos, Opera, and presumably KHTML and WebKit). I wonder
why you think you need that, though.

Does anyone know a way to determine whether a DOM object has an event
listener added to it with Element::addEve ntListener(), or if it is possible
to return a list of the added listeners, and if yes, how?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Aug 29 '07 #3
David Golightly wrote:
Also, for this an other reasons, I don't particularly care to use IE's
proprietary attachEvent at all. Though some would eviscerate me for
saying this, try using the YAHOO! UI library (http://
developer.yahoo .com/yui/) to wrap the browser differences. Your life
will be MUCH easier: YAHOO exposes YAHOO.util.Even t.getListeners, a
method that returns all (YAHOO-library) attached listeners on an
element.
Mere handling of previously registered events is hardly a justification
for using junk code.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Aug 29 '07 #4
On Aug 28, 6:18 pm, Thomas 'PointedEars' Lahn wrote:
Mere handling of previously registered events is hardly a justification
for using junk code.
You'll have to back up this assertion with something other than
vitriol.

Aug 29 '07 #5
David Golightly wrote:
On Aug 28, 6:18 pm, Thomas 'PointedEars' Lahn wrote:
>Mere handling of previously registered events is hardly a
justificatio n for using junk code.

You'll have to back up this assertion with something other than
vitriol.
Which assertion exactly?
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Aug 29 '07 #6
On Aug 28, 6:26 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
David Golightly wrote:
On Aug 28, 6:18 pm, Thomas 'PointedEars' Lahn wrote:
Mere handling of previously registered events is hardly a
justification for using junk code.
You'll have to back up this assertion with something other than
vitriol.

Which assertion exactly?
PointedEars.ASS ERT(YUI == 'junk code');

Aug 29 '07 #7
Max
On Aug 28, 6:05 pm, David Golightly <davig...@gmail .comwrote:
On Aug 28, 4:37 pm, Max <krya...@yahoo. comwrote:
Hi All,
I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any
way to do this???
Thanks,
Max

Do you need to be notified exactly *when* attachEvent was used? Or do
you come along later and inspect the element to see if it had had an
event listener attached at some point in the past?

Also, for this an other reasons, I don't particularly care to use IE's
proprietary attachEvent at all. Though some would eviscerate me for
saying this, try using the YAHOO! UI library (http://
developer.yahoo .com/yui/) to wrap the browser differences. Your life
will be MUCH easier: YAHOO exposes YAHOO.util.Even t.getListeners, a
method that returns all (YAHOO-library) attached listeners on an
element.

-David
I need to inspect the element and figure out whether it has attached
event handler or not. I'm writing an automation tool which basically
can load any URL and when page is loaded I want to inspect all
elements and see which events are attached. In case of onclick
property all I have to do just verify if element.onclick != null but
attachEvent does not affect the state of the property. I can not use
any libraries like Yahoo because I'm not the one who is writing a code
for the page.

Max

Aug 29 '07 #8
Max
On Aug 28, 6:16 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Max wrote:
I need to check if attachEvent was done to an element. The problem is
that attachEvent does not save this information anywhere. Is there
any way to do this???

(Your Question Mark key is borken.)

I don't know any. But, since attachEvent() is IE-proprietary, you could
equally use the `onclick' property, which value you can test against.
Your code would still be proprietary, but would at least support more DOMs
(including NN4, Geckos, Opera, and presumably KHTML and WebKit). I wonder
why you think you need that, though.

Does anyone know a way to determine whether a DOM object has an event
listener added to it with Element::addEve ntListener(), or if it is possible
to return a list of the added listeners, and if yes, how?

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8 300d...@news.de mon.co.uk>
Thomas,

As I mentioned in my reply to David I'm not writing a code for the
page. I need to inspect elements of the existing page. So I have the
same question about attached event listeners.

Max

Aug 29 '07 #9
On Aug 28, 9:43 pm, Max <krya...@yahoo. comwrote:
I need to inspect the element and figure out whether it has attached
event handler or not. I'm writing an automation tool which basically
can load any URL and when page is loaded I want to inspect all
elements and see which events are attached. In case of onclick
property all I have to do just verify if element.onclick != null but
attachEvent does not affect the state of the property. I can not use
any libraries like Yahoo because I'm not the one who is writing a code
for the page.

Max
Wow, I suspect there's just not going to be a solution to this
particular problem, which I rarely say, but in this case you may well
have stumped me and everyone on this list. (Yes, that's a
challenge.) For native object methods I'd recommend wrapping the
native code before the script loads and replacing it with a function
that logs each call to that function to your custom object that
records method usage. IE, however, is built defensively and won't let
you wrap COM object methods, and since attachEvent belongs to
IHTMLElement2 (which is part of the MSHTML and not the JSCRIPT
interface), this won't work. Try it. You'll get a nasty exception.

Listeners registered using attachEvent are maintained behind-the-
scenes, that is, they're kept hidden from the scope of the window
object and its children. So unless you have some way to inspect the
code running on the page for instances of attachEvent and you're able
to trace the element references used back to elements on the page,
which is clearly non-trivial, OR unless you have some way of embedding
the ShDocView component in a C# application and getting at the DOM
that way, you're probably not going to find a pure-JScript solution.

See: http://msdn2.microsoft.com/en-us/library/aa703974.aspx for more
info on attachEvent (and most everything else in the labyrinthine
annals of Internet Explorer's COM system).

-David

Aug 29 '07 #10

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

Similar topics

4
5430
by: John McCarthy | last post by:
Novice here - using notepad only ..... function MenuBarIn(E) { var i; with (document.getElementById(E.id)) {
5
14471
by: Bert | last post by:
Hello, I'm having some problems with creating a script that works on both Mozilla browsers as IE. I want to change the background color of textareas and input text fields as soon as somebody has entered something in them. The script below works perfectly in mozilla browsers (netscape 7, firefox 1,...) but doesn't in internet explorer (but it gives no
2
5211
by: jiayanxiang | last post by:
Hi: I used the following code to dynamically add a control and I tried to use attachevent to add a onClick event to the control. It doesn't seem to do anything. Any idea what might be wrong? Thanks. <HTML> <HEAD>
18
12088
by: luco | last post by:
Hi! I'm having a problem with attachEvent function. I'd like to add attachEvent dynamically to some objects so that each could execute event function with different parameter value. The question is: how to pass the parameter to event function? The following code obviously doesn't work, how should i modify it to get it to work?
10
2850
by: Peter Michaux | last post by:
Hi, Today I have been testing the event models from Netscape 4.8 and IE 4 to the current crop of browsers. I'd like to write a small event library similar in purpose to the Yahoo! UI event library but with less features and code. The Yahoo! event library is one of the best libraries in YUI but it still seems to me to have some confused code...that or I'm still confused. The Yahoo! UI library focuses on using addEventListener and
5
12599
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup', makeEventFunc1(strand)); inp.attachEvent('onchange', makeEventFunc2(strand)); individually work in IE, but when used together, only the bottom one remains active. I have also tried
1
1979
by: comicgeekspeak | last post by:
Hi there, I am trying to write a loop that will add 10 divs to the screen. Each div will have an onclick event. The function that will be called onclick requires a parameter. That parameter is dynamic based on the index of the loop. In Firefox this is no problem. However in IE I get some results that I wouldn't expect. Here is my code:
3
2014
by: Rupe | last post by:
I wish to add an event to an element, but I wish to add arguments to the calling method, eg like so: element.attachEvent('onclick',startDragDrop('arg1',arg2')) I understand this is not possible. For a non windows browser I have been successful with the following code: newA.data = "argumentText"
0
9833
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
9682
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,...
1
10617
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
10263
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
9391
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
7803
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
6989
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();...
0
5842
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3122
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.