How to detect Ctrl+V, Ctrl+C using JavaScript?

前端 未结 17 2057
走了就别回头了
走了就别回头了 2020-11-22 13:47

How to detect ctrl+v, ctrl+c using Javascript?

I need to restrict pasting in my textareas, end user should not copy and p

17条回答
  •  萌比男神i
    2020-11-22 14:39

    You can use this code for rightclick, CTRL+C, CTRL+V, CTRL+X detect and prevent their action

    $(document).bind('copy', function(e) {
            alert('Copy is not allowed !!!');
            e.preventDefault();
        }); 
        $(document).bind('paste', function() {
            alert('Paste is not allowed !!!');
            e.preventDefault();
        }); 
        $(document).bind('cut', function() {
            alert('Cut  is not allowed !!!');
            e.preventDefault();
        });
        $(document).bind('contextmenu', function(e) {
            alert('Right Click  is not allowed !!!');
            e.preventDefault();
        });
    

提交回复
热议问题