Skip to content

Instantly share code, notes, and snippets.

@webapprentice
Last active December 13, 2015 15:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save webapprentice/9844114 to your computer and use it in GitHub Desktop.
<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>
<br>
<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>
<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();
client.setText(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() {
ZeroClipboard.destroy();
} );
</script>
@AlexanderPease
Copy link

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