Here is a modification of the xdazz answer, which supports browsers that use e.button, normalize the value and save it in e.which. Added lines are what is used in the jQuery library.
function mouseDown(e) {
e = e || window.event;
if ( !e.which && e.button !== undefined ) {
e.which = ( e.button & 1 ? 1 : ( e.button & 2 ? 3 : ( e.button & 4 ? 2 : 0 ) ) );
}
switch (e.which) {
case 1: alert('left'); break;
case 2: alert('middle'); break;
case 3: alert('right'); break;
}
}
source
share