190
votes

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
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 text2clipboard.com, sorry about the plug but it works and I included helpful relevant info.RandyMorris

1 Answers

32
votes

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);
}