How to disable right click or drag and drop of images on your website (script)

2 min read

There are different ways you can use to prevent image theft from your website. For instance you may choose to disable right click, dragging and saving of images on computers and phones. Below are two types of scripts that will disable the right click menu from appearing when users right click the mouse on your website.


Script 1:


Copy and paste the code below into your header or body of a single webpage you wish to disable right click on.


The 6th line of the disable right click script contains a place to add a message. Find var message="”Right" click is disabled!”; in the script below and replace Right click is disabled! with the message you wish to send your visitors who right click on your website.

<script language="JavaScript>
<!–

//Disable right mouse click script

var message="Right click is disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
return false;
}
}

function clickNS4(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=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")

// –> 
</script>

Script 2:


Go to Header, and paste the following code.

<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;
    </script>

Once you’ve pasted the code, click Save and proceed to add custom CSS. For more help on entering custom CSS, check out the CSS tutorial for your website.  In the text box, paste the following code.

 img {
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
      user-select: none;
      -webkit-user-drag: none;
      user-drag: none;
      -webkit-touch-callout: none;
    }

Victor Mochere

I’m a literati savant, altruistic, queer laughist, critique from the non-core academia and above all it’s my conviction that in all my papers the rule of three applies. I’m the only man who smokes 10 rolls of wisdom everyday, the man who milked a lioness while nakedly seated on a python’s tail.

2 thoughts on “How to disable right click or drag and drop of images on your website (script)

  • 20th January 2018 at 3:58 pm
    Permalink

    I really like these type of posts which are written in simple writing so
    that everyone can understand it, and everyone can understand what
    message does author wants to convey.The style of yours is very unique
    but easy to understand what you want to say in this discussion. Thanks a
    lot for sharing.

    Reply
  • 20th January 2018 at 4:25 pm
    Permalink

    Everyone will get more information from this post to help the users and
    thanks to all of them.

    Reply

Leave a Reply

Your email address will not be published.