
Ưu điểm của Clipboard.js là cực kì nhẹ (2kb) và không sử dụng flash.
Cài đặt
Sử dụng npmnpm install clipboard --save
Sử dụng bower
bower install clipboard --save
Hoặc bạn có thể download trực tiếp thư viện bằng file ZIP tại đây và sử dụng.
Cách sử dụng
Thêm thư viện vào trang web bằng thẻ script<!-- 1. Define some markup -->
<button id="btn" data-clipboard-text="1">Copy</button>
<!-- 2. Include library -->
<script src="../dist/clipboard.min.js"></script>
<!-- 3. Instantiate clipboard by passing a HTML element -->
<script>
var btn = document.getElementById('btn');
var clipboard = new Clipboard(btn);
</script>
Copy nội dung trong trang từ một element khác

<!-- Target -->
<textarea id="bar">Mussum ipsum cacilds...</textarea>
<!-- Trigger -->
<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">
Cut to clipboard
</button>
Copy nội dung từ thuộc tính

<!-- Trigger -->
<button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
Copy to clipboard
</button>
Bạn có thể xem thêm các ví dụ và api từ trang chủ của project tại đây: https://github.com/zenorocha/clipboard.js
Tôi là Duyệt