nanoclipboard is a JavaScript library for copy text to the clipboard. nanoclipboard has no dependencies.
var clipboard = new NanoClipboard("#btn");
clipboard.onSuccess = function(text) {
alert("Copied: " + text);
};
clipboard.onError = function(text) {
window.prompt("Ctrl+C: ", text);
};nanoclipboard's CDN provided by jsDelivr CDN
MIT License http://www.cssscript.com/lightweight-copy-clipboard-library-nanoclipboard/
nanoclipboard is a lightweight and dependency-free JavaScript library which allows to copy any text to your local clipboard by one click.
Insert the JavaScript file nanoclipboard.js into your html page.
<script src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fnanoclipboard.min.js"></script>
Create a button and define the content you want to copy using data-clipboard-text attribute:
<button id="btn" data-clipboard-text="http://www.cssscript.com" title="Copy Me!">Copy</button>
Initialize the nanoclipboard and done.
var clipboard = new NanoClipboard("#btn");
You can also copy text from any text field like input:
<input class="url" value="https://www.cssscript.net"></input> <button id="btn" data-clipboard-selector=".url" title="Copy Me!">Copy</button>
Callback events.
clipboard.onSuccess = function(text) {
alert("Copied: " + text)
this.unselect();
};
clipboard.onError = function(text) {
window.prompt("Ctrl+C: ", text);
// this.unselect();
};