Browser meta data on paste with evt.clipboardData.getData?

672 views Asked by At

I found the following function which allows me to get the data when the user pastes text.

document.addEventListener('paste', function (evt) {
  console.log(evt.clipboardData.getData('text/plain'));
});

I'm wondering if there is a format which would allow me to get the associated meta-data? (e.g. Word formating, Excel, ect.)

Preferably a program neutral solution but even being able to get word format would be useful.

1

There are 1 answers

0
Philip Kirkbride On

From what I can tell the meta-data associated with a program (e.g. pasting between two instances of word) are completely stripped before entering the browser.

Using the following in the chrome console outputs two objects which you can click on to see some meta-data. It seems the data all has a type of html/text, ensuring that there is likely no meta-data once in the browser.

document.addEventListener('paste', function (evt) {
  console.log(evt.clipboardData.items);
});

There is also a function called getAsFile() for example evt.clipboardData.items[0].getAsFile() & also items[1] as there are always at least two items if you have text in your copy/paste buffer.

However use of this function seems to return null despite my clipboard having text.