Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi All,
In my WebApplication I have restricted user from copying and pasting content from/ to Text Box.
but in one of webpage i need to allow copy/ paste in 1 textbox.

I'm using Javascript in Master page-
JavaScript
<script type="text/javascript">

             document.onkeydown = function() {

           // JavaScript code to handle keys

   </script>

can anyone suggest how do i do it?


Thanks,
Posted
Comments
ZurdoDev 17-Jul-14 13:04pm    
Since you have code to prevent it I suggest removing that code.
Sergey Alexandrovich Kryukov 17-Jul-14 13:19pm    
Right. I personally found this effort so outrageous so I decided to put a more detailed answer; please see. :-)
—SA

Restricting clipboard copy on the Web page would be huge, huge abuse brutally violating most basic customer rights. Thanks to the Web standards, this is absolutely impossible to do. The thing is: you are talking on some operations which are fully on the client side. As soon as some page content is rendered on the client host, it is already fully on that host and belongs to the client. The customer does not have to be a software engineer to work around your limitation. For your user, it would be enough to have certain level of experience with using Web and not being a complete moron.

Therefore, you are just wasting time doing something which is highly annoying to the user trying to do the clipboard copy and, at the same time, absolutely cannot protect your information.

Don't do evil.

—SA
 
Share this answer
 
v4
You'll have to modify your code. As SA says, it is a bad practice, even though some sites do it. You could pass in the textbox ID or perhaps see what page you are on. One way, and you'll have to decide, you need to modify the code.
 
Share this answer
 
As per your question I can see that below will be the simplest way.

It would be better if you create 2 master pages on with the functionality of disabling the copy and paste and another without the same
Both of the master pages will be replica of each other.

MASTER PAGE 1
(COPY PASTE DISABLED)
-Then Followed with all of its pages

MASTER PAGE 1
(COPY PASTE ENABLED)
-Then Followed with all of its pages
 
Share this answer
 
Comments
DerekT-P 3-May-21 14:28pm    
Notwithstanding the strong advice "don't do it", the above is absolutely the wrong way to do it - it becomes a maintenance nightmare, with functionality and layout duplicated just for the sake of one page. When I need specific functionality (or not) on a page, I give the tag a unique ID and check that ID in the Javascript. One line of code but I'll let you work it if you really insist on doing it. (If there's the possibility that this functionality might ever apply to more than one page, give it a classname instead!)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900