Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML page disable copy/paste [duplicate]

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?

like image 601
R.Subramanian Avatar asked Feb 13 '14 01:02

R.Subramanian


People also ask

How do I turn off copy and paste?

To disable the copy and paste function in PDFs, you need to prevent the ability to select text with the cursor. If a user can't select the text, then they can't right-click and copy with the mouse or use Ctrl-C as a keyboard command.

How do I disable copy and paste on a website?

You can't ever disable it.. users can view the source of your page so the text is always available. If you put click handlers to disable right-click, they can turn javascript off.. The best you can try to do is make it inconvenient for people to deter them, but never can you prevent them.

How do I disable paste in HTML?

The onpaste attribute lets us prevent pasting into the form. Adding the autocomplete attribute as well as preventing drag and drop into the element. If you want to avoid the on{event} code in the HTML, you can do it the cleaner way: myElement.

How do I stop HTML from copying text from a website?

Here: How to disable text selection highlighting using CSS? -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; Disallow them from being able to answer when the window's onBlur event is fired.


1 Answers

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.

like image 135
roo2 Avatar answered Oct 01 '22 09:10

roo2