clipboard.js

clipboard.js

A modern approach to copy text to clipboard!

With 4.7K+ stars to it's repo with a modern approach to copy text coded with ES2015/6 classes, No Flash. Just 2kb!

Zeno Rocha's clipboard.js undoubtedly is the nmotw!

It makes use of Selection and execCommand APIs.

Get it: npm install --save clipboard.js

Sample usage:_

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var clipboard = new Clipboard('.btn');

clipboard.on('success', function(e) {
    console.info('Action:', e.action);
    console.info('Text:', e.text);
    console.info('Trigger:', e.trigger);

    e.clearSelection();
});

clipboard.on('error', function(e) {
    console.error('Action:', e.action);
    console.error('Trigger:', e.trigger);
});

In your HTML:

1
2
3
4
5
6
7
<!-- Target -->
<input id="foo" value="https://github.com/zenorocha/clipboard.js.git">

<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
    <img src="assets/clippy.svg" alt="Copy to clipboard">
</button>

GIF FTW!

clipboard.js

Suggest a module

Comments