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

前端 未结 17 2131
走了就别回头了
走了就别回头了 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:43

    Another approach (no plugin needed) it to just use ctrlKey property of the event object that gets passed in. It indicates if Ctrl was pressed at the time of the event, like this:

    $(document).keypress("c",function(e) {
      if(e.ctrlKey)
        alert("Ctrl+C was pressed!!");
    });
    

    See also jquery: keypress, ctrl+c (or some combo like that).

提交回复
热议问题