I\'ve seen plenty of questions and answers on SO and elsewhere that talk about right click events and how to catch and handle them with JavaScript, generally using the
Sure, just add a onmousedown
listener, check which mouse was pressed:
JS:
document.getElementById("test").onmousedown = function(event) {
if (event.which == 3) {
alert("right clicked!");
}
}
HTML:
<button id="test">Test</button>
Demo: http://jsfiddle.net/Jmmqz/
http://jsfiddle.net/jqYN5/ is this what you are looking for? Adding context-menu
:
<input type="button" value="click me" id="btn">
<button id="btn2">right click</button>`
document.getElementById('btn').onclick = function() {
alert('click!')
}
document.getElementById('btn2').oncontextmenu = function() {
alert('right click!')
}
You can make use of "context Menu" also :
document.getElementById('btn2').oncontextmenu = function() {
alert('right click!')
}
Or, with perhaps a bit more beginner level understanding:
<script type="text/javascript">
function mouseclick(ele, e) {
if (e.type == 'click') {
alert('Left Click Detected!');
}
if (e.type == 'contextmenu') {
alert('Right Click Detected!');
}
}
</script>
<a href="/"
onclick="mouseclick(this, event)"
oncontextmenu="mouseclick(this, event)" >link name</a>