193

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?

Boaz
  • 19,892
  • 8
  • 62
  • 70
mager
  • 4,813
  • 8
  • 29
  • 30
  • 7
    From what I understand, you can not access the clipboard without user action. The javascript clipboard functionality has been disabled in most current browsers as it is a possible security risk. You can use some of the dynamic flash overlay type stuff like zeroclipboard but can be kinda complicated and not always stable. I developed a flash element that you might want to look at http://text2clipboard.com, sorry about the plug but it works and I included helpful relevant info. – RandyMorris Jul 30 '11 at 06:30

1 Answers1

33

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);
}
Hasturkun
  • 35,395
  • 6
  • 71
  • 104
halocursed
  • 2,451
  • 5
  • 27
  • 34