J
john_woo
Hi,
I need to implement API by which all onclick envets in same document
can be in flexible control (disable/enable on demand).
I tried the followings:
1. overwrite onclick function:
if (window.captureEvents){
window.captureEvents(Event.CLICK);
window.onclick=myfunction;
}
else{
document.captureEvents(Event.CLICK);
document.onclick=myfunction;
}
document.addEventListener("click", myfunction, true); //or
document.attachEvent("click", myfunction);
2. then in myfunction:
if (event.stopPropagation) event.stopPropagation();
else event.cancelBubble = true; //or
if (event.preventDefault) event.preventDefault();
else event.returnValue = false;
However, the above can only overwrite default behavior, can't be
applied to those buttons which are associated with specific functions/
handlers;
Then traversing through document tree to find out and overwrite those
functions. This leads to big problem - when enabling onclick events,
those specific handling functions gone!
I'm wondering, what is the right way to design/implement such API?
Thanks,
I need to implement API by which all onclick envets in same document
can be in flexible control (disable/enable on demand).
I tried the followings:
1. overwrite onclick function:
if (window.captureEvents){
window.captureEvents(Event.CLICK);
window.onclick=myfunction;
}
else{
document.captureEvents(Event.CLICK);
document.onclick=myfunction;
}
document.addEventListener("click", myfunction, true); //or
document.attachEvent("click", myfunction);
2. then in myfunction:
if (event.stopPropagation) event.stopPropagation();
else event.cancelBubble = true; //or
if (event.preventDefault) event.preventDefault();
else event.returnValue = false;
However, the above can only overwrite default behavior, can't be
applied to those buttons which are associated with specific functions/
handlers;
Then traversing through document tree to find out and overwrite those
functions. This leads to big problem - when enabling onclick events,
those specific handling functions gone!
I'm wondering, what is the right way to design/implement such API?
Thanks,