posted 17 years ago
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?