✂️ Modern copy to clipboard. No Flash. Just 3kb gzipped 📋 https://clipboardjs.com
Go to file
2015-09-19 18:03:31 -07:00
dist Breaks code into two classes 2015-09-19 18:03:31 -07:00
src Breaks code into two classes 2015-09-19 18:03:31 -07:00
.editorconfig Hello world 2015-09-17 23:15:24 -07:00
.gitignore Adds base website by using some bower dependencies 2015-09-19 00:18:33 -07:00
bower.json Removes files that should belong only to gh-pages 2015-09-19 03:23:09 -07:00
package.json Breaks code into two classes 2015-09-19 18:03:31 -07:00
README.md Renames "data-value" to "data-text" 2015-09-19 02:25:46 -07:00

clipboard.js

A modern approach to copy & cut to the clipboard. No Flash. No dependencies. Just 1kb.

Install

You can get it using bower:

bower install clipboard --save

Or download as ZIP.

Usage

First, you need to instantiate it using a selector. This selector corresponds to the trigger element, usually a <button>.

new Clipboard('.btn');

The easiest way to copy some content to the clipboard, is to include a data-text attribute in your trigger element.

<button class="btn" data-text="Lorem ipsum">Copy</button>

Another way of doing it, is to copy the content from an another element. You can do that by adding a data-target attribute in your trigger element. The value you include on this attribute needs to match another's element id attribute.

<p id="foo">Lorem ipsum</p>
<button class="btn" data-target="foo">Copy</button>

Additionally, you can define a data-action attribute to specify if you want to either copy or cut content. If you omit this attribute, copy will be used.

<input id="foo" value="Lorem ipsum"></inpu>
<button class="btn" data-action="cut" data-target="foo">Copy</button>

As you may expect, the cut action only works on <input> or <textarea> elements.

Browser Support

This project relies on both Select API and execCommand API. When combined, they're supported in the following browsers.

Chrome logo Firefox logo Internet Explorer logo Opera logo Safari logo
42+ ✔ 41+ ✔ 9+ ✔ 29+ ✔ Nope ✘

License

MIT License © Zeno Rocha