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;
}

4 Comments:

Anonymous said...

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

আলোর ছটা said...

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

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

George said...

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

আলোর ছটা 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 ]]---