I'm trying to make a zoomable image block in an HTML page using javascript. Now zooming in is finished by capturing Doubleclick event and some simple functions. Problem is here that I have some elements (div tags like tile) and want to have a function called when right clicked on some of them. How can I do this?
Asked
Active
Viewed 4,556 times
3
-
Search for "contextmenu". – Teemu Jan 16 '15 at 15:39
-
Duplicate of : http://stackoverflow.com/questions/2405771/is-right-click-a-javascript-event – violator667 Jan 16 '15 at 15:39
2 Answers
5
You can use the contextmenu event:
<div oncontextmenu="javascript:alert('Right Click Performed!');return false;">
Right click on me!
</div>
And then add a listener:
el.addEventListener('contextmenu', function(ev) {
ev.preventDefault();
alert('Right Click Performed!');
return false;
}, false);

Francesco
- 1,383
- 7
- 16
0
javascripts event.button
function will give you the mouse button you clicked.
<img onMouseDown="alert(event.button)" src="yourimage" />
right click should return 2 but best check each browser

Brian van Rooijen
- 1,906
- 1
- 14
- 10