Andreas Remdt
Andreas Remdt

Reputation: 91

HTML5 Clipboard API: paste custom format

We are using a 3D CAD application which allows to copy the 3D data in a special format to the clipboard. We now want to paste this 3D data (basically it's structured as XML) in the browser.

I tried a lot with the HTML5 Clipboard API, but besides text and HTML nothing works, the clipboardData is always emtpy...

Even if I log the type, besides text and HTML, it's empty: console.log(event.clipboardData.types);

Retrieving data with event.clipboardData.getData('application/x-egr-eai-basket-cutbuffer-uncompressed') doesn't work, too.

Is it even possible to paste such a custom format in the browser?

Upvotes: 2

Views: 1847

Answers (1)

Beep
Beep

Reputation: 122

It seems custom data formats for the clipboard are not directly supported. According to the specification in W3C:

If data type is text/plain:

  1. Ensure encoding is correct per OS and locale conventions
  2. Normalize line endings according to platform conventions
  3. Place text on clipboard with the appropriate OS clipboard format description

Otherwise, if data is of a type listed in the mandatory data types list

Place part on clipboard with the appropriate OS clipboard format description

Otherwise

This is left to the implementation..

This suggests to me that any custom types will be ignored by browsers. As such, I'd advise simply saving the XML as a string to the clipboard and retrieving it using event.clipboardData.getData('text/plain')

Upvotes: 2

Related Questions