Return a variable value with Zeroclipboard

Asked

Viewed 56 times

2

I’m using this library https://github.com/zeroclipboard to copy text by clicking the user’s Clipboard button. I’m trying to find a way to change its functioning a little, but without success.

The basic usage of the library is:

<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 intend to change is when the user clicks on the id="d_clip_button" div he has to return a JQUERY value that is in a variable to inside data-Clipboard-text, in this way I can generate values dynamically from a database, I did several tests, but I could not find the solution, is it possible to do this, or does this library only work with static text? If the answer is YES, I have some way to do what I want?

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!}}" );
});
  • Perfect, working properly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.