简体   繁体   中英

Intercept clipboard information when pasting to handsontable

Description of the problem and things I have tried:

To keep it simple, I'm looking for a way to handle information being pasted from clipboard to a handsontable. I was reading a post from another stackoverflow post that to retrieve pasted information from clipboard using jQuery:

  $("#haras_excel_like_table").bind("paste", function(e){
      // access the clipboard using the api
      var pastedData = e.originalEvent.clipboardData.getData('Text');
      console.log(pastedData);
  });

However, that does not work on the handsontable (it does work on the body).

I then tried adding the bind event to each cell in the handsontable, however that did not work as well.

I have also looked through all handsontable methods to see if they thought about implementing something like this, but apparantely they haven't. Methods handsontable

Question:

Does anyone have a solution on how to intercept pasted information from the clipboard before actually pasting it to the handsontable? Thanks.

This seems to work for some reason.

  $(document.body).on("paste", function(e){
      // access the clipboard using the api
      var pastedData = e.originalEvent.clipboardData.getData('text');
      console.log(pastedData);
      if($(e.target).prop('nodeName') == 'TEXTAREA'){

      }
  });

but is not the optimal solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM