clipboard-copy
Lightweight copy to clipboard for the web
The goal of this package is to offer simple copy-to-clipboard functionality in modern web browsers using the fewest bytes. To do so, this package only supports modern browsers. No fallback using Adobe Flash, no hacks. Just 30 lines of code.
Unlike other implementations, text copied with clipboard-copy
is clean and
unstyled. Copied text will not inherit HTML/CSS styling like the page's background
color.
Works in the browser with browserify!
install
npm install clipboard-copy
usage
const copy = require('clipboard-copy')
button.addEventListener('click', function () {
copy('This is some cool text')
})
API
copy(text)
Copy the given text to the user's clipboard.
Note: in most browsers, copying to the clipboard is only allowed if copy()
is
triggered in direct response to a user gesture like a 'click'
or a 'keypress'
.
comparison to alternatives
clipboard-copy
(this package): 542 bytesclipboard-js
: 1.83 kBclipboard
: 3.19 kB
license
MIT. Copyright (c) Feross Aboukhadijeh.