Copying text to the clipboard shouldn’t be hard. It should not 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, to make copying text to clipboard easy to code and maintain no matter the user’s browser.
npm install clipboard --save or bower install clipboard --save
- Chrome 42+
- Firefox 41+
- IE 9+
- Opera 29+
- Safari (Not supported)
Although copy/cut operations with execCommand aren’t supported on Safari yet (including mobile), it gracefully degrades because Selection is supported.
That means you can show a tooltip saying Copied! when success event is called and Press Ctrl+C to copy when error event is called because the text is already selected.
- Website: http://zenorocha.github.io/clipboard.js
- Downloads: https://github.com/zenorocha/clipboard.js/archive/master.zip
- Developer: zenorocha.com
- On Twitter: @zenorocha