Emerson F
Emerson F

Reputation: 845

How to install ZeroClipboard?

As per instructions at their website: https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md

I copy and pasted the minimal example at the bottom of the page, and copied the 2 files

ZeroClipboard.swf & ZeroClipboard.js

into the root of my website.

I can't seem to get the button working. Am I missing something?

Upvotes: 2

Views: 1723

Answers (1)

Dzseti
Dzseti

Reputation: 447

In the basic example you need to include the ZeroClipboard.js script. I added:

<script src="ZeroClipboard.js"></script>

to the html head section. Then - which was not so clear for me either - the main.js script needs to be added after the button. I didn't reference the file (which isn't in the package as far as I could tell), but included the script directly - this way:

<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>

<script type="text/javascript">
    var client = new ZeroClipboard( document.getElementById("copy-button") );

    client.on( "ready", function( readyEvent ) {
    // alert( "ZeroClipboard SWF is ready!" );

    client.on( "aftercopy", function( event ) {
    // `this` === `client`
    // `event.target` === the element that was clicked
    event.target.style.display = "none";
    alert("Copied text to clipboard: " + event.data["text/plain"] );
  } );
} );
</script>

Hope this helps somebody (more than one year on I gues you have either solved it or moved on!!)

Upvotes: 4

Related Questions