this content was originally posted here.
clipboard copy js
for copying things to the clipboard, like the click to copy.
Include the script
add a field to copy to the clipboard
<input id="clipme" value="https://github.com/zenorocha/clipboard.js.git">
add a button or link to copy it and bind it to the id clipme
<a class='btn btn-primary' data-clipboard-target="#clipme">Copy to Clipboard</a>
Well this is a bit of a fail it seems to be targeting the script src from above... hmm.
Ah its cos i forgot to start the plugin... doh!
Also have to add this selector to the elements that are going top be running the copy and paste
Ok it works now, it should highlight the text in the field above when you click the button, it copied to my clipboard ok.
Seems like a bit of effort to get working. But its not too bad once you remember to:
- add the main script clipboard.min.js
- add a field or element to copy with correct #id
- add the button with the data binding data-clipboard-target="#id"
- initialise the script and target the button new Clipboard('#id');
thats the basic usage, for more detailed usage go to the official site