Reputation: 63
I am looking for a way to change the following javascript so that when a user clicks on right button, it shows a custom message in alert box.
<script type="text/javascript">
function mousedwn(e) {
try { if (event.button == 2||event.button == 3) return false; }
catch (e) { if (e.which == 3) return false; }
}
document.oncontextmenu = function() { return false; }
document.ondragstart = function() { return false; }
document.onmousedown = mousedwn;
</script>
Upvotes: 0
Views: 1488
Reputation: 7375
Try the below code for disabling right click with alert/without alert.
<script language=JavaScript>
<!--
//edit by unwanted
var message="PUT YOUR MESSEGE HERE";
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
// -->
</script>
Thanks,
Siva
Upvotes: 1