Here's the function I use:
var ieButtons = { "1": "left", "2": "right", "3": "leftright", "4": "middle" };
function getMouseButton(evt) {
if (typeof evt.which == "number") {
// Non-IE case. Works in everything apart from Opera < 8
return (evt.which < 2) ? "left" :
( (evt.which == 2) ? "middle" : "right" );
} else {
// IE case
return ieButtons[evt.button] || "unknown";
}
}
document.onmousedown = function(evt) {
evt = evt || window.event;
window.alert( getMouseButton(evt) );
};
Jan Wolter's article on mouse events is seemingly less well-known than his one on key events but is just as good, and knocks quirksmode into a cocked hat: http://unixpapa.com/js/mouse.html
Having just looked at the jQuery code, it looks as though it normalizes the which property of the event correctly (1 for left, 2 for middle, 3 for right), although without IE's nice feature of reporting multiple simultaneous button presses.