HTML5 Clipboard API plaintext and formatting

A few months ago I was tasked with creating a copy/paste facility within the FP webapp. It worked (across a subset of browsers) but it didn’t copy formatting. Improving it wasn’t a priority until recently when a colleague of mine was tasked with improving the functionality.

It turns out the fix was really quite simple. I’d been copying the content into a textarea and since textareas only contain plaintext, thats what was being copied to the clipboard. To copy formatted text all that was required was to create a hidden “standard” element and copy the content from there, abracadabra formatted clipboard content.

And some sample code:

Ben Squire

Read more posts by this author.

Leicestershire, United Kingdom https://squired.co.uk