1

Possible Duplicate:
How to select all text in a textbox and copy it to clipboard using JavaScript/jQuery?
Copy text to the client’s clipboard using jQuery

I need a javascript, jquery function for copy to clipboard functionality. I know following code but it works in IE only:

holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");

I see some tutorials which are suggestion some swf files. I have used some of them like http://www.steamdev.com/zclip/ but it is not working.

Please suggest solution to it.

Community
  • 1
  • 1
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

2 Answers2

0

There isn't any cross-browser way to copy data to the clipboard via javascript (it's regarded as a security hole) - it can be done with the assistance of a small flash applet, but this of course isn't fully cross platform.

One of the cheats I've used before is to create a prompt with a default value in which makes it slightly easier for the user to copy-and-paste the information without having to highlight it in the page. But this doesn't really solve the problem. All you can do is make the copy-and-paste as little effort as possible.

PhonicUK
  • 13,486
  • 4
  • 43
  • 62
0

The mainstream way of doing this is via a SWF object. ZeroClipboard is a neat project which deals with this.

James
  • 5,137
  • 5
  • 40
  • 80