Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy to Clipboard with a click? 1

Status
Not open for further replies.

javierdlm001

Technical User
Jun 28, 2008
264
CA
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!

JDL
 
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
 
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!';
}
});

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

clipboard.on('success', function(e) {
console.log(e);
});

clipboard.on('error', function(e) {
console.log(e);
});
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top