Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy value to clipboard without user interaction #270

Closed
RogerKang opened this issue Jun 27, 2016 · 1 comment
Closed

Copy value to clipboard without user interaction #270

RogerKang opened this issue Jun 27, 2016 · 1 comment

Comments

@RogerKang
Copy link

RogerKang commented Jun 27, 2016

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?

@zenorocha
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants