0

I'd like to have a 'COPY' button that uses Javascript to copy the contents of a TEXTAREA onto the clipboard, but the only solution I've managed to find is one that uses Flash, which I don't want to do (JQuery Clipboard).

The user will be copying some code from inside the textarea on my website to a HTML editor (via the clipboard) so I also can't use any elegant hidden DIVs, as they won't be accessible to the editor.

Does anyone know if it's possible?

[EDIT: I've looked at this solution and it uses Flash which I don't want].

Community
  • 1
  • 1
Steve
  • 599
  • 4
  • 15
  • Possible [duplicate](http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript) ... – HamZa Nov 23 '12 at 15:56
  • Not a duplicate - that solution you've linked to is one I spotted before posing my question - that solution uses Flash as one method and Manually (Ctrl C/V) as the other. My question was whether any alternatives to those exist. – Steve Nov 23 '12 at 16:04
  • I know, because it's near impossible (or really difficult) to achieve for security reasons. – HamZa Nov 23 '12 at 16:06

2 Answers2

0

Why the solution you mention (and several others) use Flash?
Because for security reasons, some browsers like Firefox limit the access the the clipboard.
Putting stuff on the clipboard should be relatively safe, but being able to read the clipboard can be dangerous (if you copied your credit card number, for example...).

Firefox has a specific API to enable such operations, but it requires a user operation (IIRC), which makes it not very practical.

Flash has no problem with this security problem, so that's why lot of sites use this solution.

PhiLho
  • 38,673
  • 6
  • 89
  • 128
0

For security reasons, it's not possible to access user's clipboard directly. The Flash solution is a workaround.

Another possibility can be seen here. It basically prompts the user to copy the text manually.

Community
  • 1
  • 1
Matheus Azevedo
  • 838
  • 6
  • 18