javascript tutorial - [Solved-5 Solutions] Copy to the clipboard in javascript - javascript - java script - javascript array
Problem:
What is the best way to copy text to the clipboard?
Solution 1:
- The user is presented with the prompt box, where the text to be copied is already selected. Now it's enough to press
Ctrl
+C
andEnter
(to close the box) -- and voila! - Now the clipboard copy operation is SAFE, because the user does it manually (but in a pretty straightforward way). Of course, works in all browsers.
Solution 2:
If we want a really simple solution (takes less than 5 minutes to integrate) and looks good right out of the box, then Clippy is a nice alternative to some of the more complex solutions.
Clippy
It was written by a co-founder of Github. Example Flash embed code below:
Solution 3:
Reading and modifying the clipboard from a webpage raises security and privacy concerns. However, in Internet Explorer, it is possible to do it. We found this example snippet:
Solution 4:
clipboard.js is a small, non-flash, utility that allows copying of text or html data to the clipboard. It's very easy to use, just include the .js and use something like this:
Solution 5:
ZeroClipboard is the best cross-browser solution I've found: