Copy into clipboard

How can I copy a short text in clipboard? I know I should have a form with a disabled textarea with text in it and a button topy that text into clipboard, but how can I do it? Would you please suggest a standalone js for this job?

There isn’t one. JavaScript does not normally have access to the clipboard. There are some browsers where it does but in those browsers it is generally recommended to turn that option off as it represents a significant security hole.

So how is the way to do so? With html? How?

With your mouse or keyboard. eg.
left click select, right click copy
ctrl+shift+arrow, ctrl+c

Like @Mittineague said.

Also to select Unix-style:
Double click for a whole word.
Tripple click for a whole line.

You can set the content as selected using JavaScript. It is just the copy part that you have to do manually.

So isn’t possible to copy a texarea field with just a button click?

As mentioned above, maybe one browser supports it, but generally no, it is not possible Don’t bother going this route.

You could probably implement some sort of copy (if you wanted) but your own version of “copy”. Not anything clipboard related.

Then you get into “is this even worth it” argument…

It is possible to copy content server-side, just not to a user’s clipboard.

What exactly are you wanting to do? With more details we may be able to help you find a solution.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.