• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prevent multiple event handlers on same element.

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are attachign to a new window to listen to events on that window:

winHandle=window.open("....jsp");
if( window.attachEvent ) {
winHandle.document.attachEvent('onclick',detectType);
winHandle.document.attachEvent('onkeyup',detectType);}
In the detectType function, we attach and eventhandle to the individual element,based on the element type

function detectType (e)
{
var targ;
if (!e) var e=winHandle.event;
if (e.target){targ=e.target;}
else if(e.srcElement){targ=e.srcElement;}
if (targ.nodeType==3){targ=targ.parentNode;}

var tagName=targ.tagName;

switch(tagName)
{
......
case "INPUT":
targ.attachEvent("ondeactivate",capturecontent);
break;
default:
targ.attachEvent("onblur",capturecontent);
break;

}
...
}

Now in some cases,both the mouse and kep events would fire and cause the event handler to be attached twice.
Is ther some way to detect if an event handler has already been attached,to avoid re-attaching it?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(.....eventHandler)alert("hi");


Eric
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
i could not understand the answer.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, if you want to have single event for an element then use this method for attaching events:

element.onClickCHANGED = do;

:roll:
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(document.getElementById("foo").onclick)alert("I have an onclick event");
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
true,but this identifies only the ones which i define inline(within the script).
Thid would not identify the one in a separate javascript file through attachevent/addeventhandler model,isnt it?
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ranadhir Nag:
true,but this identifies only the ones which i define inline(within the script).
Thid would not identify the one in a separate javascript file through attachevent/addeventhandler model,isnt it?



I think, you can't get the function name associated with the event in case of advanced model of event attachment.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All I can say is have you actually tried it or are you assuming it?

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic