3
I found several articles saying that this type of action with Javascript is something "risky" and many browsers prevent this to be done. Yet, in the articles I read, they said that the only way to do something similar is by using Flash.
So I Googled for solutions and found the Zeroclipboard, but I couldn’t use it. I tried it this way:
$(document).ready(function(){
var client = new ZeroClipboard( $('button') );
client.swfPath = 'ZeroClipboard.swf'; // está na pasta do projeto
$('button').on('click', function(){
client.setData("text/plain", "TESTE");
});
});
What is wrong?
The button loses the effect of Hover, the flash is picking it up normally. But when I click the button, the string "TEST" is not copied to the Clipboard.
No error appears on console.
Ultimately: Is there any other way to do this? Others plugins?
Try:
var client = new ZeroClipboard( $('button')[0] );
– bfavaretto
Related: Way cross-browser copy text to Clipboard (Clipboard).
– Renan Gomes