This question already has an answer here:
这个问题已经有了答案:
- How do I copy to the clipboard in JavaScript? 49 answers
- 如何在JavaScript中复制到剪贴板?49岁的答案
The workflow is simple:
工作流很简单:
- You click inside a textarea.
- 点击一个文本区域。
- The text is copied to the client's clipboard.
- 文本被复制到客户端的剪贴板。
- Display notice to the user.
- 向用户显示通知。
How do you do it?
你是怎么做到的?
5 个解决方案
#1
53
Started the search here and found https://github.com/terinjokes/zClip - works perfectly for me.
在这里开始搜索,发现https://github.com/terinjokes/zClip -对我来说是完美的。
#2
32
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.
从浏览器兼容性的角度来看,在Javascript中复制剪贴板是一项棘手的任务。最好的方法是使用一个小闪光灯。它将在每个浏览器上运行。您可以在本文中查看它。
Here's how to do it for Internet Explorer:
以下是如何使用ie浏览器的方法:
function copy (str)
{
//for IE ONLY!
window.clipboardData.setData('Text',str);
}
#3
7
There are a bunch of options over here: http://www.jquery4u.com/plugins/jquery-copy-clipboard-4-options/#.UFbo1YriYz0
这里有很多选项:http://www.jquery4u.com/plugins/jquerycopy -clipboard-4-options/#.UFbo1YriYz0
#4
5
I was in need of something like this, and this one seems promising:
我需要这样的东西,这个看起来很有希望:
http://github.com/mojombo/clippy
http://github.com/mojombo/clippy
Here's a simple jquery plugin for it as well: http://gist.github.com/66579
这里还有一个简单的jquery插件:http://gist.github.com/66579
#5
5
This one is cross browser and works with Flash 10.
这是一个跨浏览器,使用Flash 10。
http://beckelman.net/post/2009/01/22/Copy-to-Clipboard-with-ZeroClipboard-Flash-10-and-jQuery.aspx
http://beckelman.net/post/2009/01/22/Copy-to-Clipboard-with-ZeroClipboard-Flash-10-and-jQuery.aspx
#1
53
Started the search here and found https://github.com/terinjokes/zClip - works perfectly for me.
在这里开始搜索,发现https://github.com/terinjokes/zClip -对我来说是完美的。
#2
32
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.
从浏览器兼容性的角度来看,在Javascript中复制剪贴板是一项棘手的任务。最好的方法是使用一个小闪光灯。它将在每个浏览器上运行。您可以在本文中查看它。
Here's how to do it for Internet Explorer:
以下是如何使用ie浏览器的方法:
function copy (str)
{
//for IE ONLY!
window.clipboardData.setData('Text',str);
}
#3
7
There are a bunch of options over here: http://www.jquery4u.com/plugins/jquery-copy-clipboard-4-options/#.UFbo1YriYz0
这里有很多选项:http://www.jquery4u.com/plugins/jquerycopy -clipboard-4-options/#.UFbo1YriYz0
#4
5
I was in need of something like this, and this one seems promising:
我需要这样的东西,这个看起来很有希望:
http://github.com/mojombo/clippy
http://github.com/mojombo/clippy
Here's a simple jquery plugin for it as well: http://gist.github.com/66579
这里还有一个简单的jquery插件:http://gist.github.com/66579
#5
5
This one is cross browser and works with Flash 10.
这是一个跨浏览器,使用Flash 10。
http://beckelman.net/post/2009/01/22/Copy-to-Clipboard-with-ZeroClipboard-Flash-10-and-jQuery.aspx
http://beckelman.net/post/2009/01/22/Copy-to-Clipboard-with-ZeroClipboard-Flash-10-and-jQuery.aspx