if left click or right click statement in javascript code example
Example 1: javascript detect right click
el.addEventListener('contextmenu', function(ev) {
ev.preventDefault();
alert('success!');
return false;
}, false);
Example 2: javascript detect right click
document.body.onclick = function (e) {
var isRightMB;
e = e || window.event;
if ("which" in e) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.which == 3;
else if ("button" in e) // IE, Opera
isRightMB = e.button == 2;
alert("Right mouse button " + (isRightMB ? "" : " was not") + "clicked!");
}
Example 3: if left click or right click statement in javascript
alert("Right mouse button " + (isRightMB ? "" : " was not") + "clicked!");