Lightweight module to copy text to the clipboard in modern browsers (< 1kB minified)
npm install clipbrd
import * as clipboard from 'clipbrd';
if (clipboard.isSupported()) {
button.addEventListener('click', () => {
clipboard.copy('Custom text');
});
}
Copy text
to the clipboard.
Returns a boolean
of whether it succeeded.
Must be called in response to a user gesture event, like click
or keyup
.
Check if copy is supported, that way you can hide copy buttons from the UI.
Returns a boolean
- hackernoon.com/copying-text-to-clipboard-with-javascript - Original Hackernoon article
- copy-text-to-clipboard - Pulled fixes from battle tested realization
- clipboard.js - Pulled support method
MIT License