28 July 2008

Detect Right Button Click in JavaScript

function IsRightButtonClicked(e) // e : mouse event
var rightclick = false;
e = e || window.event;
if (e.which)
rightclick = (e.which == 3);
else if (e.button)
rightclick = (e.button == 2);
return rightclick;


Brian said...

I see how the function works, but how do you pass e to the function?

Alor Chhota said...

the mouse event 'e' can be found like below:

document.getElementById("myDiv").onmousedown = function(e)
alert("Right Button Down");

geowalker said...

This function only works with MS-IE, FireFox and Google Chrome know the right button as: 1!

Alor Chhota said...

I tested it in IE 6, IE 7, Firefox 2, Firefox 3, Google Chrome, Safari. It works just fine.


© 2007 t!ps n tr!cks: Detect Right Button Click in JavaScript

Template unik dari rohman

---[[ Skip to top ]]---