I have used oncontextmenu to call a function on mouse right-click, it is working fine on Firefox but causing problem on IE, context menu also appears along with the function.
I just need to call same function having some parameters on right and left click in pure JavaScript.
<html>
<script>
function mouseDown(e,param) {
if (parseInt(navigator.appVersion)>3) {
var clickType=1;
if (navigator.appName=="Netscape") clickType=e.which;
else clickType=event.button;
if (clickType==1) {
alert("left" +param);
}
if (clickType!=1) {
alert('right' + param);
}
}
return true;
}
</script>
<body>
<a href="javascript:void(0)"
onclick="mouseDown(event,'test1');"
oncontextmenu="mouseDown(event,'test2');">mouse</a>
</body>
</html>
You need to
return false;in the contextmenu event in order to prevent the default menu from showing up.Bear in mind that some browsers (Firefox in particular) defaults to not allowing JavaScript to block context menus, so you may encounter problems there.