-3

I have looked at other code, and I just can't get any of it to work. I'm able to suppress the right-click context menu, but I need more than that. I need every right-click to act as if the left button were clicked, and I need to know exactly where to put it in my html code. This is a hot issue, as I can't progress on an important project until I can make this happen reliably. HELP!

  • 1
    before you can get help you should show what you've tried. A listener on right clicks that emits a left click event should do it for you, but its hard to know without knowing anything about your code. – TheCog19 Sep 07 '17 at 13:08
  • Possible duplicate of [How to distinguish between left and right mouse click with jQuery](https://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery) – Surreal Sep 07 '17 at 13:14
  • I used the "oncontextmenu" function to suppress the right-click menu. Now I need something to allow the right-click to function as a left-click as well. I am NOT an experienced coder. I haven't touched any of this stuff since about 2003! – Curt Pangracs Sep 07 '17 at 13:53
  • More info - this code presents an MP4 with "hotspots" which are used to move a tutorial forward when the proper area is selected. Unfortunately, this is a tutorial for a piece of software that has right-click context menus. Since I want the MP4 to progress properly, I need the hotspot to be activated as if it were a left-click, even though the tutorial is telling the user to right-click. I am using Techsmith's Camtasia v.9 to create this tutorials, and I am editing their auto-produced HTML file that allows for controlling the production through clicks on these "Hotspots". – Curt Pangracs Sep 07 '17 at 14:02

2 Answers2

0

You can use the following code to convert the right button click into left button click.

Here when you click inside the div the right button click is converted into left button. So that when you press left or right button both will behave on the same way.

 $(document).ready(function() {
      $("#rightclickDemo").bind('contextmenu', function(event) {
         if (event.which == 3)
         {
           // prevent right click from being interpreted by the browser:
            event.preventDefault(); 
  
            $(this).click(); // simulate left click
         }
      });

       $('#rightclickDemo').click(function() {
           $(this).html("Left clicked!");
      });
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
   
</head>
<body>
  <p>This is a web page Demo.</p>

  <div id="rightclickDemo" style="width:200px; height:100px; background-color: orange">
    Click me with the right or left mouse button. Both will work as left button clicked!
  </div>
</body>
</html>
Jino Shaji
  • 1,097
  • 14
  • 27
0

I found my answer after MUCH research. this code works exactly the way I want it to! Added the jquery.min.js to my file structure and it works perfectly for standalone use!

<script src="scripts/jquery.min.js"></script>

<script type="text/javascript">
$(document).on("contextmenu", function(e){
    e.preventDefault();
    e.target.click();
});
</script>