Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<p>This text will be copied when you click the button</p>
<p id='copy_this_text' style="width: 50%; border: 1px solid #888">Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod <i>tempor incididunt ut labore</i> et dolore magna
aliqua. <strong>Ut enim ad minim veniam</strong>, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<button id="copy-button">Copy to Clipboard</button>
<p>Paste into this box with Ctrl/Cmd-V to show that it worked.</p>
<textarea cols='60' rows='10'></textarea>
<script src="javascripts/ZeroClipboard.js"></script>
// Specify where the Flash movie can be found if not in root folder for web site
ZeroClipboard.config( { moviePath: 'javascripts/ZeroClipboard.swf' } );
var client = new ZeroClipboard( $("#copy-button") );
client.on( 'load', function(client) {
client.on( 'datarequested', function(client) {
var text = $('#copy_this_text').text();
// callback triggered on successful copying
client.on( 'complete', function(client, args) {
console.log("Text copied to clipboard: \n" + args.text );
// In case of error - such as Flash not being available
client.on( 'wrongflash noflash', function() {
} );
Copy link

AlexanderPease commented Jan 6, 2015

This page is load. 'load' and 'datarequested' are no longer viable zeroclipboard methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment