Copy Textarea with Zero Clipboard

Chris Burton picture Chris Burton · Sep 9, 2012 · Viewed 20.8k times · Source

Is there a way to copy the textarea to the clipboard without a button?

What I'm trying to do is have a Short URL display on my site so when you click the link (or text), it copies to the clipboard and fades out with new text fading in that says "Copied!". The links/text will automatically be generated with bit.ly with my custom domain.

Example:

Short URL: shrt.lnk/abc123 (Regular) Short URL: Copied! (On Click)

Anyone have an idea how to do this?

Answer

Triforcey picture Triforcey · Sep 9, 2015

You could try clip-j instead. Here it is. This is a pure JavaScript solution that takes advantage of document.execCommand('copy'); witch is supported by all major browsers, with other commands to work around the limitation of having to be able to see a text input, do you doing see anything! Plus this doesn't have to work through a button, clicking a link will work just fine!