Get started with clipboard-polyfill CDN
MIT licensed
Clipboard-polyfill: library for native copy-paste on unsupported elements.
Tags:- clipboard
- HTML5
- copy
- copying
- cut
- paste
- execCommand
- setData
- getData
- polyfill
Stable version
Copied!
How to start using clipboard-polyfill CDN
// Import clipboard-polyfill from the CDN
import ClipboardJS from 'https://cdn.cdnhub.io/clipboard-polyfill/4.0.2/es6/clipboard-polyfill.es6.js';
// Create a new instance of ClipboardJS
const clipboard = new ClipboardJS('.copy-button');
// Define the button element with the copy-button class
const copyButton = document.querySelector('.copy-button');
// Add an event listener to the button for click events
copyButton.addEventListener('click', () => {
// Get the text to be copied
const textToCopy = copyButton.getAttribute('data-text');
// Attempt to copy the text using clipboard.writeText()
clipboard.writeText(textToCopy)
.then(() => {
console.log('Text copied to clipboard successfully!');
})
.catch((err) => {
console.error('Failed to copy text: ', err);
});
});
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
All versions
0.1.0
0.1.1
0.1.2
0.2.0
0.3.0
0.3.1
0.3.2
0.3.3
0.3.4
0.3.5
0.3.6
0.4.2
0.4.3
0.5.1
0.5.2
2.0.0
2.0.1
2.0.2
2.0.3
2.1.0
2.1.4
2.2.0
2.3.0
2.3.1
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.4.7
2.5.0
2.5.2
2.5.3
2.5.4
2.6.0
2.7.0
2.8.0
2.8.1
2.8.3
2.8.4
2.8.5
2.8.6
3.0.0
3.0.0-beta
3.0.0-beta3
3.0.0-pre1
3.0.0-pre2
3.0.0-pre3
3.0.0-pre4
3.0.0-pre5
3.0.1
3.0.2
3.0.3
4.0.0
4.0.0-rc1
4.0.0-rc2
4.0.0-rc3
4.0.0-rc5
4.0.0-rc6
4.0.0-rc7
4.0.0-rc8
4.0.1
4.0.2
*** 4.1.0