You can avoid the single click handler when you doubleclick,
but it requires setting a timeout for the single click handler,
and cancelling it if a doubleclick is called on.
- function oneclickevent(e){
-
e= window.event || e;
-
var who= e.srcElement || e.target;
-
var s= who.id || who.tagName;
-
s+='\n'+e.type;
-
if(!window.clicktimer) window.clicktimer= setTimeout(function(){
-
alert(s);
-
window.clicktimer= undefined;
-
},
-
500);
-
}
-
function twoclickevent(e){
-
clearTimeout(clicktimer);
-
e= window.event || e;
-
var who= e.srcElement || e.target;
-
var s= who.id || who.tagName;
-
alert(s+'\n'+e.type);
-
window.clicktimer= undefined;
-
}
var el= document.getElementById('mybutton');
el.onclick= oneclickevent;
el.ondblclick= twoclickevent;
The delay for the single click may be a pain,and difficult to set for all users.
And some people will click multiple times which can send a single click after the double click returns-
Besides, it is tough to implement for keyboard access-
consider making your second event a click+shiftkey,
and handle it without a delay either way.