» » Without Flash and relying on any JS library to copy and cut text to clipboard

 

Without Flash and relying on any JS library to copy and cut text to clipboard

Author: bamboo06 on 2-04-2016, 15:50, views: 4400

1
We place a copy button on the page, it is mainly used to facilitate the user to copy a complex text links and the like, the conventional approach is to rely on Flash through JS, even by means of a huge jQuery js library to implement text copied to the clipboard. Today, I give you about is a very modern, no flash, does not rely on any other js very small plug-in libraries, it is called clipboard.js.


HTML
Clipboard.js is first loaded as local files.
<script src="clipboard.min.js"></script> 

And then add to copy or cut the contents of a text field and a button in the body.
<input id="foo" value="http://www.goocode.net"> 
<button class="btn" data-clipboard-target="#foo" aria-label="Copy Success!">Copy</button> 

Here, we use the HTML5 data- attribute, used to locate the target object is copied, it points to a text field #foo, dub is #foo the value content, aria-label attribute defines the information copied successfully, with the copy the results to prompt information.
There is a property of data-clipboard-action, which defines the current operation is to copy or cut, copy default, when data-clipboard-action = "cut", then, click on the button will cut the text, with the same operating WORD . Of course, the cut operation applies only to text and textarea.
We can also do not need to input and textarea elements such content to be copied, we can be content to be copied by ata-clipboard-text attribute is defined on a button, click the button can be copied to the corresponding ata-clipboard-text content.
<button class="btn" data-clipboard-text="Text to be copied" aria-label="Copy Success">Copy</button> 


javascript
The following sentence is added to the code before and save it to open a browser, click on the Copy button.
new Clipboard('.btn'); 

Of course, we can do further processing, such as when the copy is complete, copy the success prompted some information more friendly, just run the following code:
var clipboard = new Clipboard('.btn'); 
 clipboard.on('success', function(e) { 
    var msg = e.trigger.getAttribute('aria-label'); 
    alert(msg); 
    e.clearSelection(); 
}); 

Category: HTML5 / Plugins

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
28 April 2017 00:01

CesMamEbra

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Ampicillin Amoxicillin And Ticarcillin For Dogs Buy Cialis Legitimate Cialis Canada Canadian Pharmacy Rip Off viagra online Priligy Costo En Venezuela Buy Viagra Online Malaysia accutane online fast deliverey Viagra 50 Mg Durata Effetto Levitra Medicament Belgique cialis Cephalexin Substrate Composition Du Clomid generic cialis Levitra Generico Online Vendita Cialis Daily 5 Mg Price Cheap Cialis Xenical Sans Ordonnance Xenical Dapoxetine Uk cialis online Amiloride Propecia Online Purchase cialis Viagra E Emicrania Viagra Rouge buy cialis Levitra Pfizer Cialis Quito viagra cialis Propecia Prostate Ezonlinepharmacy cialis price Online No Prescrption Pharmacy K Cl ou acheter du viagra For Sale Generic Pyridium 200mg Internet Propecia Finasteride Benefits buy priligy dapoxetine online safely Viagra Pillole Avantages De Clomid is alli back on sale Zithromax Pimples Healthy Man Viagra Radio Ad rx canada pharmacy accutane Kamagra Cialis Viagra

Information
Comment on the news site is possible only within (days) days from the date of publication.