How to disable copy and cut in TextBox?

后端 未结 5 1874
一个人的身影
一个人的身影 2021-02-10 06:46

In my webpage I want to disable copy and cut option in context menu on textbox.

相关标签:
5条回答
  • 2021-02-10 06:56

    You can also add a javascrip function to show a alert

        <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 讨论(0)
  • 2021-02-10 06:58

    Try this

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

    for more see this link

    0 讨论(0)
  • 2021-02-10 07:10

    This is my first post and I hope it will help. Try this one:

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

    It will work for copy, paste, cut, and delete on most of the input controls.

    0 讨论(0)
  • 2021-02-10 07:14
    <asp:TextBox ID="TextBox1" runat="server" oncopy="return false">  </asp:TextBox>
    
    0 讨论(0)
  • 2021-02-10 07:14

    Not sure if you're looking for a non asp way but I just found out about on cut method in JavaScript. Do the following for your input:

    <input oncopy='prevent()>
    
    <script>
    function prevent()
    {
     event.preventDefault();
    }
    </script>
    

    Works for me. Tested on chrome. Also disables copying from the context menu. Additionally this works for oncut and onpaste methods. Still trying to find a way for ondelete though.

    0 讨论(0)
提交回复
热议问题