views:

9401

answers:

4

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?

A: 

http://www.geekpedia.com/tutorial126%5FClipboard-cut-copy-and-paste-with-JavaScript.html

machineghost
AFAIK there is no jQuery method for doing this, so you just have to resort to Javascript
machineghost
jQuery *is* Javascript.
KyleFarris
+5  A: 

This plugin is cross-compatible with all browsers and works well:

http://plugins.jquery.com/project/clipboard

KyleFarris
Unfortunately this plugin no longer works with the current version of Flash (>= 10.0.0)
macek
@macek: That brings me much sadness. Hopefully there will eventually be some new standard JavasScript API in the near future. There may be security risks associated with it, though, so it's hard to say what the good ol' W3C will come up with.
KyleFarris
@KyleFarris, there are sites that are using this type of functionality though, and it still works with Flash >= 10.0.0. http://github.com and http://bit.ly come to mind...
macek
+2  A: 

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);
}
halocursed
+1  A: 

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

Erlend Halvorsen