How to disable right mouse click on image/webpage/website.


 

Did you know that you can disable the copy and paste function on your web pages? Of course you did, that’s why you’re here, to see how it’s done.

How to disable selecting the contents from the website?
How to disable copy and paste contents on webpage/website?

1. Apply this code in your html document inside the <body> tag

“ ondragstart=’return false’ onselectstart=’return false’ ” – to disable copy and paste
For Example:

<body ondragstart=”return false” onselectstart=”return false”>

By applying this code, we can easily disable the drag and drop option in order to avoid copying the contents

Use this script in your html document before closing the >/head< tag

<script language=JavaScript>

  var message="Function Disabled!";
	
  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>

By using this script, we can disable the Right Click Mouse Button in order to avoid draging/copying the images and contents

This script is specially useful to avoid copying the images

3. give security to the contents by using the css elements in body tag

EX: in css file

body {
  user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
}

OR

You can also use bleow javascript code for disable right click.

<script type="text/JavaScript">

  function killCopy(e){
    return false
  }

  function reEnable(){
    return true
  }
  
  document.onselectstart=new Function ("return false")
  
  if (window.sidebar){
    document.onmousedown=killCopy
    document.onclick=reEnable
  }
</script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s