How to developed Copy to Clipboard using ZeroClipboard


1. Download ZeroClipboard Flash file(ZeroClipboard.swf) and Javascript file(ZeroClipboard.js) from this link : http://zeroclipboard.org/

2. Now initialize ZeroClipboard scripts


 <script type="text/javascript" src="js/ZeroClipboard.js"></script>
 <script type="text/javascript">
    function initialize() {
        ZeroClipboard.setMoviePath('js/ZeroClipboard.swf');
        clip = new ZeroClipboard.Client();
        clip.setHandCursor(true);
        //event
        clip.addEventListener('mousedown', function() {
            clip.setText(document.getElementById('Link').value);
        });
        clip.addEventListener('complete', function(client, text) {
            alert('copied: ' + text);
        });
        //glue it to the button
        clip.glue('copy');
    }
    jQuery('document').ready(function() {
        var clip = null;
        initialize();
    });
 </script>


3. Now Active copy to clipboard functionality to a html anchor link


  <form>
     <input readonly="true" type="text" id="Link" value="https://ziyedbd.wordpress.com/"/>
  </form>
  <a id='copy' >Copy To Clipboard</a>	

Advertisements