How to create “Copy to clipboard” button?
-
I’d like to have the “Copy to clipboard” functionality with CodeMirror code blocks.
On my website, there are a lot of helpful code snippets that are frequently copied by readers, and it would make it easier to copy them by a single click instead of selecting everything – especially when the code block is getting bigger.
I do know about
document.execCommand('copy')
, but as far as I can see there is no easy way to select everything in order to put it into the hidden<textarea>
element. I do know about other ways to copy via JavaScript as well.You might want to consider adding this as an optional functionality to the plugin itself, as it seems to be very user-friendly, and big websites such as Google or Bootstrap use it with their code blocks.
- The topic ‘How to create “Copy to clipboard” button?’ is closed to new replies.