Thursday, March 1, 2018

detect copy, paste and cut behavior with jQuery

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <style type="text/css">
        span{
            color:green;
            font-weight:bold;
        }
        </style>

 <label>Text Box : </label>
            <input id="textA" type="text" size="50" value="Copy, paste or cut any text here" />



<script type="text/javascript">
        $(document).ready(function() {
            $("#textA").bind({
                copy : function(){
                $('#message').text('copy behaviour detected!');
                },
                paste : function(){
                return false;  /*you can't paste in textbox*/
                //$('#message').text('paste behaviour detected!');
                },
                cut : function(){
                $('#message').text('cut behaviour detected!');
                }
            });
        });
        </script>

No comments:

Post a Comment