Cut, Copy, and Paste text from a Web Page to Clipboard

Author: MikeW    Date: 2016-01-13 22:46:49 UTC   

Want to make it easy to copy and paste some random piece of text to the clipboard? Well this can be accomplished using HTML with surprising ease. All you need to do is add a little JavaScript. Here are two examples, one with text box and one with a text area.

This trick can be used for any bit of text you want to copy to the clipboard a lot. Very useful for storing an e-mail address or user name that you need to copy and paste repeatedly.


These examples copy a command line for the Maven build tool.

Text Box Example


<input onclick=";" type='text' size="40" value='mvn archetype:generate -DgroupId=com.example -DartifactId=app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false' />

Text Area Example


<textarea cols="50" rows="4" onclick=";">mvn archetype:generate -DgroupId=com.example -DartifactId=app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false</textarea>