Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How to copy to Clipboard with a click?

How to copy to Clipboard with a click?

How to copy to Clipboard with a click?

Hi all,

Joe Burns shows here how to set up a button that when clicked, you get whatever text was being host in its code, copied to your Clipboard. Hence you could paste it somewhere.
Apparently it no longer works with modern browsers due to security reasons.
Does anyone know of an alternative?
Thanks guys!


RE: How to copy to Clipboard with a click?

This is great!

Thanks a bunch spamjim :)


RE: How to copy to Clipboard with a click?

Now that I had a closer look, I could use a bit of clarification :)
I understand that "Copying and Cutting Values of Textarea and Input" & "Copying Element innerHTML" go in the <body> tag.
But what about "Target and Text Functions" & "Events" ? Do I need a <script> tag for these? If so, does it go in the <head> tag, or in the <body>?

Thanks in advance

RE: How to copy to Clipboard with a click?

In another words...

Where am I to put this below:

Target and Text Functions
// Contents of an element
var clipboard = new Clipboard('.copy-button', {
target: function() {
return document.querySelector('#copy-target');

// A specific string
var clipboard = new Clipboard('.copy-button', {
text: function() {
return 'clipboard.js is awesome!';

var clipboard = new Clipboard('.btn');

clipboard.on('success', function(e) {

clipboard.on('error', function(e) {

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close