IMO (and quirksmode's ), the IE bitmask is better than the W3C version, because you can detect combo clicks like left + right or middle + left. It offers a bit more flexibility. Both (pressing all the pressed buttons and the new button pressed) will be even better.
I donβt know the library or script that is already doing what you are trying to do, I think most developers simply ignore combo clicks if they donβt want to apply a specific action to the combo click. In addition, it is quite complicated, you will have to detect both onmousedown and onmouseup for the entire document and record the state of the mouse buttons. Then on the element on which you want to use your magic, subtract the previous state of the mouse from the new one. Something like (verified):
if (document.attachEvent) { (function () { var mState = 0; document.documentElement.attachEvent("onmousedown", function () { mState += event.button; }); document.documentElement.attachEvent("onmouseup", function () { mState -= event.button; }); document.getElementById("jim").attachEvent("onmousedown", function () { var realButton = event.button - mState; alert(realButton);
Of course, there are only about a million things that can go wrong with this script. For example, in my example, I have a warning window that appears with the actual state of the button. If you release the button while the notification dialog is raised, the document will not be detected by the mouse, and it will throw everything out of impact. Similarly, any mouseup or mousedown events on other elements that stop propagating to the documentElement event handler can cause it to break.
If you want my advice, display a message on a combined mouse click, guess the "right" mouse button or ignore them all together. Any of these options is better than a hacker approach.
source share