Return a variable value with ZeroClipboard

2

I'm using this link library to copy text by clicking the button for the user's clipboard. I'm trying to find a way to change it a bit, but to no avail.

The basics of using the library are:

<html>
<body>
<div id="d_clip_button" class="clip_button" data-clipboard-text="Copy Me!"  title="Click to copy." style="border:1px solid black; padding:20px;">Copy To Clipboard</div>

<script type="text/javascript" src="ZeroClipboard.js"></script>
<script type="text/javascript">
  var client = new ZeroClipboard( document.getElementById('d_clip_button') );
</script>
</body>
</html>

What I want to change is when the user clicks on the div of id="d_clip_button" it has to return a JQUERY value that is in a variable into data-clipboard-text , so I can dynamically generate values from a database, I did several tests, but I could not find the solution, can I do this, or does this library only work with static text? If the answer is YES, do I have any way of doing what I want?

    
asked by anonymous 04.08.2015 / 18:37

1 answer

2

Just look at the library documentation.

var client = new ZeroClipboard( document.getElementById("d_clip_button") );
client.on( "copy", function (event) {
  var clipboard = event.clipboardData;

  // Pode usar um AJAX aqui para resgatar valores
  // do banco de dados, se quiser.

  clipboard.setData( "text/plain", "Copy me!" );
  clipboard.setData( "text/html", "<b>Copy me!</b>" );
  clipboard.setData( "application/rtf", "{\rtf1\ansi\n{\b Copy me!}}" );
});
    
04.08.2015 / 18:55