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!
Asked
Active
Viewed 1,023 times
-3
-
1before 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 Answers
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
-
Okay, that looks like it would work! Where do I put this particular code? Is it in the body or does it need to run as a separate script somewhere? I'm NOT up on my coding, since the last time I did any html was back in about 2003! – Curt Pangracs Sep 07 '17 at 13:21
-
This particular script can be place on a separate java script file or inside the html page within the script tag within the body or head tag both will work fine – Jino Shaji Sep 07 '17 at 13:24
-
I'm thinking I need to create a .js file to run this locally? I can't have this point to anything external, since this will be on a CD/DVD or run without access to the internet... – Curt Pangracs Sep 07 '17 at 13:24
-
-
If you provide your code along with this question that will be more useful for others and it will help to get better idea about the question. – Jino Shaji Sep 07 '17 at 13:29
-
-
-
-
I don't know yet, because i can't get it to work. Let me send you the full code somehow... – Curt Pangracs Sep 07 '17 at 13:36
-
-
I tried adding the script with the script tags, but it didn't work. I'm sure I'm not doing something right. Can I email you the html file? – Curt Pangracs Sep 07 '17 at 13:40
-
Just remove this thing 'oncontextmenu="return false;" ' from your body tag and then use my sample code – Jino Shaji Sep 07 '17 at 13:41
-
Just send via email. My email-id is jinoshajiv@gmail.com. Don't forget to accept my answer if it is useful. – Jino Shaji Sep 07 '17 at 13:43
-
No, that brings up the right-click context menu, and it does not act as a left-click... – Curt Pangracs Sep 07 '17 at 13:43
-
I need the context menu suppressed AND the right-click to function as a left-click... – Curt Pangracs Sep 07 '17 at 13:45
-
-
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>

Curt Pangracs
- 11
- 3