copy.js - simple copy text to clipboard in the browser
Note: This post is over 11 years old. The information may be outdated.
DEPRECATED (2025): This article describes an unmaintained library from 2016. For modern copy-to-clipboard functionality, use the native
navigator.clipboardAPI instead, which is supported in all modern browsers and requires no dependencies.
Simple copy to clipboard. No Flash.
Install
You can get it on bower.
bower install copy --save
Or npm, too.
npm install copy-js --save
If you're not into package management, just download a ZIP file.
Setup
First, include the script located on the dist folder.
<script src="dist/copy.min.js"></script>
Or load it from CDN provider.
<script src="//cdn.rawgit.com/duyetdev/copy.js/master/dist/copy.min.js"></script>
Usage
Just copy:
copy('hello world.')
With callback:
copy('hello world', function (err) {
if (err) console.log('Some thing went wrong!')
console.log('Copied!')
})
That's it!
Modern Alternative (2025)
Instead of using copy.js, use the native Clipboard API:
// Copy text to clipboard
navigator.clipboard.writeText('hello world')
.then(() => console.log('Copied!'))
.catch((err) => console.error('Failed to copy:', err))
The native API is supported in all modern browsers and requires no external dependencies.
Visit project source code here: https://github.com/duyet/copy.js
Related Posts
Yarn: A new package manager for JavaScript
Facebook has launched Yarn
calc.js - evaluate expressions for Math
Flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices. Powerful and easy to use.
Resting và Spreading JavaScript Objects
Resting và spreading càng ngày được ưa chuộng vì sự tiện lợi của nó, sau đây là 7 tricks với JavaScript objects.
Javascript Weekly #9
Javascript Weekly #9: Date-DNS, chi tiết về các bản cập nhật mới của V8, React và Angular.  ## [date-fns: A Modern...