How to copy text to the client's clipboard usi

2018-12-31 22:12发布

问题:

This question already has an answer here:

  • How do I copy to the clipboard in JavaScript? 50 answers

The workflow is simple:

  1. You click inside a textarea.
  2. The text is copied to the client\'s clipboard.
  3. Display notice to the user.

How do you do it?

回答1:

Started the search here and found https://github.com/terinjokes/zClip - works perfectly for me.



回答2:

Copying to the clipboard is a tricky task to do in Javascript in terms of browser compatibility. The best way to do it is using a small flash. It will work on every browser. You can check it in this article.

Here\'s how to do it for Internet Explorer:

function copy (str)
{
    //for IE ONLY!
    window.clipboardData.setData(\'Text\',str);
}


回答3:

There are a bunch of options over here: http://www.jquery4u.com/plugins/jquery-copy-clipboard-4-options/#.UFbo1YriYz0



回答4:

I was in need of something like this, and this one seems promising:

http://github.com/mojombo/clippy

Here\'s a simple jquery plugin for it as well: http://gist.github.com/66579



回答5:

This one is cross browser and works with Flash 10.

http://beckelman.net/post/2009/01/22/Copy-to-Clipboard-with-ZeroClipboard-Flash-10-and-jQuery.aspx