0

Me and my team are trying to solve this issue .

Does anyone know the jquery code to perform the action of a left click button when right mouse button is clicked

For Example: Say I right click on a link , instead of opening a pop up window I need it to go the link's destination . In other wants I need the right click to do the action of a mouse left click .

Tried searching the web , but was of no use . Hence posting this as my last option .

Would really appreciate any help .

Thanks in advance .

jat
  • 6,940
  • 3
  • 14
  • 10
  • this might help: http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – Th0rndike Nov 19 '12 at 09:11

1 Answers1

0

Try this, for example (updated):

<html>
<body oncontextmenu="return false;">
<a href="#">Test Link</a>
<script src="jquery-1.8.2.min.js"></script>
<script>
$(document).ready(function()
{
    $(document).mousedown(function(e)
    {

        if (e.button == 2) //right click
        {
         e.preventDefault();
         e.stopPropagation();
         e.stopImmediatePropagation();
         document.body.style.backgroundColor = "green";
         return false;
        }
        if (e.button == 0)//left click
        {
         e.preventDefault();
         e.stopPropagation();
         e.stopImmediatePropagation();
         document.body.style.backgroundColor = "blue";
         return false;
        }

    });
});
</script>
</body>
</html>

And if you want to prevent the default behavior, use e.preventDefault(); , e.stopPropagation(); e.stopImmediatePropagation(); before changing the background color.

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
  • Gie me a min . Will give it a try.Thank You – jat Nov 19 '12 at 10:02
  • Wow . It stopped the pop up window from opening when right clicked . But it did not take me to the URL when right clicked . – jat Nov 19 '12 at 10:07
  • You need to implement your own click link behavior (because the code above cancel the default one) - simply put document.location.href='URL here'; – Bud Damyanov Nov 20 '12 at 07:52