Clipboard.js – A modern approach to copy text to clipboard

Clipboard.js – A modern approach to copy text to clipboard


SHARE & COMMENT

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.

Install

npm install clipboard --save

or 

bower install clipboard --save

Browser Support

This library relies on both Selection and execCommand APIs. The second one is supported in the following browsers.

  • 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.

Reference

 

SHARE & COMMENT