-1

My current solution does not work, could you help me figure out why?

This is my javascript:

$(function() {

var clip = new ZeroClipboard(document.getElementById("copy"));

clip.on("ready", function() 
{

clip.on("copy", function(event) {

var clipboard = event.clipboardData;

clipboard.setData(attr.('href'),$("#text-to-copy"));


});

});

});

The html I'm using:

<a id="text-to-copy" th:href="@{http://localhost:8080/{id}(id=${url})}"

th:text="@{/{id}(id=${url})}" data-clipboard-target="text-to-copy"></a>

<div class="row" style="padding-top: 20px; padding-left: 20px;">

<input type="button" class="btn btn-default btn-radio" id="copy" name="copy" 
value="copy" />
Olavi Sau
  • 1,647
  • 13
  • 20
  • 1
    Possible duplicate of [How do I copy to the clipboard in JavaScript?](http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Joost Nov 03 '15 at 08:41

1 Answers1

0

Well your supposed to use click() not copy.

$(function() {

    var clip = new ZeroClipboard(document.getElementById("copy"));

    clip.on("ready", function() {

        clip.click(function(event) {
            var clipboard = window.clipboardData;
            clipboard.setData(attr.('href'),$("#text-to-copy"));
        });
    });
});
Olavi Sau
  • 1,647
  • 13
  • 20