Skip to content

diglink/nanoclipboard

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nanoclipboard

nanoclipboard is a JavaScript library for copy text to the clipboard. nanoclipboard has no dependencies.

Usage

var clipboard = new NanoClipboard("#btn");

clipboard.onSuccess = function(text) {
	alert("Copied: " + text);
};

clipboard.onError = function(text) {
	window.prompt("Ctrl+C: ", text);
};

CDN

nanoclipboard's CDN provided by jsDelivr CDN

https://www.jsdelivr.com/projects/nanoclipboard

Demo

License

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.

How to use it:

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(); };

About

JavaScript library for copy text to the clipboard.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 67.2%
  • HTML 32.8%