Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any other alternative to capturing text on Ctrl+V

I am trying to capture the text on Ctrl+V event as below..

  1. Creating a textarea in the page and setting height 0px and width 0px. like below

      <textarea id="a" style="height:0px;width:0px"></textarea>
    
  2. On pressing V key i am setting the focus to that textarea and then using Ctrl+V button. Like below..

     shortcut.add("X",function() {
      $('#a').focus();
     });
     // In between user have to press Ctrl+V to paste the content
     shortcut.add("V",function() {
      alert($('#a').val());
     });
    

I think this as a most inefficient approach and waiting for valuable suggestions to improve this..

like image 483
Exception Avatar asked Nov 05 '22 10:11

Exception


1 Answers

You can attach events to the paste event.

$('textarea').bind('paste', function() {
   // Hello, Mr. Paste!
});
like image 93
alex Avatar answered Nov 11 '22 12:11

alex