How to disable copy and cut TextBox?

On my webpage, I want to disable the copy and cut function in the context menu in the text box.

+5
source share
5 answers

You can also add javascrip function to display warning

    <script language="javascript" type="text/javascript">
            function nocopy()
    {
                alert("Copying is not allowed!");
                return false;
    }
   </script>


<asp:TextBox ID="TextBox1" runat="server" oncopy="return nocopy()">  </asp:TextBox>
0
source
<asp:TextBox ID="TextBox1" runat="server" oncopy="return false">  </asp:TextBox>
+8
source

. , , . :

<asp:TextBox ID="someId" runat="server" oncopy="return false" onpaste="return false" oncut="return false" ondelete="return false"></asp:TextBox>

, , .

+5

Not sure if you are looking for a way without asp, but I just found out about the cut method in JavaScript. To enter, do the following:

<input oncopy='prevent()>

<script>
function prevent()
{
 event.preventDefault();
}
</script>

It works for me. Tested on chrome. Also disables copying from the context menu. In addition, this works for the oncut and onpaste methods. However, trying to find a way for ondelete, though.

+1
source

try it

     <asp:TextBox ID="txtPrevent" runat="server"  oncopy="return false"
         oncut="return false">
        </asp:TextBox>

See link for more details.

0
source

All Articles