1
document.addEventListener('paste', function(e){
    clipboard = e.clipboardData.getData();
    console.log(clipboard);
});

This is my test code. I want to get clipboardData, but it comes out "42 Uncaught TypeError: Failed to execute 'getData' on 'DataTransfer': 1 argument required, but only 0 present." when I try to paste a picture.

When I just paste, I can see

DataTransfer {dropEffect: "none", effectAllowed: "uninitialized", items:DataTransferItemList, types: Array[1], files: FileList}

There is some data.

But if I try to open, it shows

dropEffect:"none"
effectAllowed:"uninitialized"
files:FileList
items:DataTransferItemList
types:Array[0]
__proto__:DataTransfer

There is no data.

MaoQ
  • 11
  • 3
  • You have to specify the type of data you are looking for. It is accessible under `evt.clipBoardData.types` so you probably can just do `var clipboard = evt.clipboardData.getData(evt.clipboardData.types[0])`. For a more complete solution see [this answer](http://stackoverflow.com/a/6804718/3702797) to a dupe. – Kaiido Apr 14 '16 at 05:07
  • That helps a lot! Thanks! But if I want to get the files, what should I do? – MaoQ Apr 14 '16 at 05:18
  • 1
    I have tried evt.clipboardData.files. But when I paste, it comes out "FileList {length: 0}". – MaoQ Apr 14 '16 at 05:33
  • 1
    For reading files, you can refer [this](http://stackoverflow.com/questions/6333814/how-does-the-paste-image-from-clipboard-functionality-work-in-gmail-and-google-c) post – jeetaz Apr 14 '16 at 05:45

0 Answers0