disable right click web

one of ways to protect images from download is using disable right click (save image as). This function will check whether user right click at image or not, if yes then it will simply return nocontext:
here is the code :

<!-- disable click kanan -->
<script type='text/javascript'>
function nocontext(e) {
var clickedTag = (e==null) ? event.srcElement.tagName : e.target.tagName;
if (clickedTag == "IMG") {
return false;
document.oncontextmenu = nocontext;
  • copy above code inside <head>....</head> of your html.
  • to disable right click for all target type remove the conditional statement if(clickedTag == "IMG") 
    • function nocontext(e) {
      return false
warning :
a lot of users are not comfortable with web without right click enabled, you must consider another way to protect your images. you may use watermarking or create overlay transparent image to do that. I will post it later.
Have a nice web !

Post a Comment