28

In a HTML page user should not be allowed to copy a text, but at the same time I want to give option for the user to select a particular text (for highlighting purpose). That means CTRL+C should be disabled and CTRL+A should be enabled.

Can anyone tell me how to do this?

Klaster_1
  • 11,206
  • 8
  • 62
  • 70
R.Subramanian
  • 321
  • 1
  • 3
  • 4
  • 1
    you can use CSS: ` -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; ` – Shawn Oct 25 '16 at 21:03

2 Answers2

65

You cannot prevent people from copying text from your page. If you are trying to satisfy a "requirement" this may work for you:

<body oncopy="return false" oncut="return false" onpaste="return false">

How to disable Ctrl C/V using javascript for both internet explorer and firefox browsers

A more advanced aproach:

How to detect Ctrl+V, Ctrl+C using JavaScript?

Edit: I just want to emphasise that disabling copy/paste is annoying, won't prevent copying and is 99% likely a bad idea.

Community
  • 1
  • 1
roo2
  • 5,781
  • 2
  • 29
  • 45
  • 3
    _"annoying"_ Totally! I was trying to copy **public** information, and the copy function is disabled. It makes no sense. _"won't prevent copying"_ Yes, I just blanked out `oncopy` in Firefox Inspect Element to read `oncopy=""` and the Copy function worked fine. I was able to copy anything I wanted from the page :) – ADTC Feb 12 '18 at 16:51
35

You can use jquery for this:

$('body').bind('copy paste',function(e) {
    e.preventDefault(); return false; 
});

Using jQuery bind() and specififying your desired eventTypes .

Vainglory07
  • 4,713
  • 8
  • 41
  • 76