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

前端 未结 17 2044
走了就别回头了
走了就别回头了 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条回答
  •  攒了一身酷
    2020-11-22 14:48

    Short solution for preventing user from using context menu, copy and cut in jQuery:

    jQuery(document).bind("cut copy contextmenu",function(e){
        e.preventDefault();
    });
    

    Also disabling text selection in CSS might come handy:

    .noselect {  
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
         user-select: none;
    }
    

提交回复
热议问题