admin管理员组文章数量:1404924
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?
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?
Share Improve this question asked Jan 16, 2015 at 15:35 ShahoShaho 1822 silver badges15 bronze badges 2- Search for "contextmenu". – Teemu Commented Jan 16, 2015 at 15:39
- Duplicate of : stackoverflow./questions/2405771/… – violator667 Commented Jan 16, 2015 at 15:39
2 Answers
Reset to default 5You 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);
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
本文标签: eventsHow to capture right click on a specify element in javascriptStack Overflow
版权声明:本文标题:events - How to capture right click on a specify element in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744865277a2629309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论