βοΈ Modern copy to clipboard. No Flash. Just 3kb gzipped π
clipboard.js
Modern copy to clipboard. No Flash. Just 3kb gzipped.
Why
Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.
That's why clipboard.js exists.
Install
You can get it on npm.
npm install clipboard --save
Or if you're not into package management, just download a ZIP file.
I like the
document.execCommand
approach, but you should look for the solution created by Zeno Rocha : github.com/zenorocha/clipboard.jszenorocha / clipboard.js
βοΈ Modern copy to clipboard. No Flash. Just 3kb gzipped π
clipboard.js
Why
Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.
That's why clipboard.js exists.
Install
You can get it on npm.
Or if you're not into package management, just download a ZIP file.
Setup
First, include the script located on the
dist
folder or load it from a third-party CDN provider.Now, you need to instantiate it by passing a DOM selector, HTML element, or list of HTML elements.
Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guessβ¦