CanIUse.com shows that all major browsers have at least partial Clipboard API support while FF has full support: https://caniuse.com/#feat=clipboard
However, I cannot find any tutorials or simple examples of how to write to the clipboard using HTML5 (no flash).
Does anyone know what exactly partial support means, is this feature usable? If it only worked in Chrome/FF that would be sufficient for my needs.
I recently did an intense research on the W3C Clipboard API (which is up to this writing still in the working draft stage) support in the following browsers (latest versions):
Chrome and Firefox both support the W3C Clipboard API. You can read and write data to the clipboard using the
getData
andsetData
methods: https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboardDataYou can set data in different MIME types (even custom ones). Although anything different from
text/plain
andtext/html
won't be readable in other browsers, only the one you set the data in.Edge supports the W3C Clipboard API with the restriction that you can only write data with the MIME type
text/plain
(ortext
). Anything else is going to throw an exception. But there is a hack using a contenteditable div with which you can write data with thetext/html
MIME type too.The hack can be found here: https://stackoverflow.com/a/30905277/434742 (look for "UPDATE: COPY KEEPING THE TEXT FORMAT" in the answer)
Internet Explorer does not support the W3C Clipboard API. There is a custom implementation available though. But even that has the same restriction as Edge meaning you can only write data with the MIME type
text/plain
(ortext
). But the hack for Edge above also works for Internet Explorer. Moreover you can also only read data with the MIME typetext/plain
(ortext
). But there is another hack using a contenteditable div with which you can read data with thetext/html
MIME type too.The hack can be found here: https://stackoverflow.com/a/6804718/434742 (look for "Solution #2" in the answer)
TL;DR: You can copy and paste text including formatting (HTML) in all browsers mentioned above. Some workarounds are needed for Edge and especially Internet Explorer though.