Actually, I konw a user iteraction is required(like a click).
But the click operation can be triggered by javascript but a real click operation, so I think this design is not really meanningful for developers(unless browsers make some limitation for some cases).
Like below:
function copyToClipboard(selector, text) {
var clipboard = new Clipboard(selector,{
text:function(trigger){
return text;
}
});
clipboard.on('success', function(e) {
e.clearSelection();
clipboard.destroy();
});
clipboard.on('error', function(e) {
clipboard.destroy();
});
setTimeout(function(){
$(selector).click();
},100);
}
So why don't we open the function 'copy to clipboard from variable' directly?
Due to security restrictions imposed by browser vendors, user interaction is required in order copy/cut to work. A simulated click event using JavaScript does not work as this would enable clipboard poisoning.
Most helpful comment
Due to security restrictions imposed by browser vendors, user interaction is required in order copy/cut to work. A simulated click event using JavaScript does not work as this would enable clipboard poisoning.