Disable Right Clicking On Your Site
Did you ever wanted to disable right clicking on your site? There are number of ways to do this.
1. From JavaScript
Add the following script to the head of your site.
<script type="text/javascript"> function a(){
if(document.all){return false;}
}
function b(e){
if(document.layers||(document.getElementById&!document.all)){ if(e.which==2||e.which==3){return false;}
}
}
if(document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=b;
}else{
document.onmouseup=b;
document.oncontextmenu=a;
}
document.oncontextmenu=new Function("return false"); </script>
2. From jQuery
First you need add jquery library to your page.
<script src="jquery.min.js"></script>
Download jquery .Add the following code to disable mouse right click.
<script type="text/javascript">
$( "body" ).contextmenu(function(e) {
e.preventDefault();
return false;
});
</script>
OR
<script type="text/javascript">
$(document).ready(function () {
//Disable full page
$("body").on("contextmenu",function(e){
return false;
});
//Disable part of page
$("#id").on("contextmenu",function(e){
return false;
});
});
</script>
Don't Disable Right Click
It isn’t generally a good idea. Why?
Unprofessional - Its not a good practice to do this.
Pointless - even though you did this there are ways to achieve the options in the right click (Shortcut Keys)
Comments
Post a Comment