Last active
December 13, 2015 15:26
-
-
Save webapprentice/9844114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This page is load. 'load' and 'datarequested' are no longer viable zeroclipboard methods