Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • script for copy to clipboard

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 223
    Comment on it

    Copy to clipboard.. You can see this option in most of the blogs. You can simply click on the link and it will copy the text which set as target. Today we are going to discuss the implementation of this feature. We can see different ways to do the same but due to the security reasons those scripts are not working. Thanks to Zeroclipboard which is basically a library. You can simply implement this feature with the help of this library. Zeroclipboard library using pitch of flash as well as touch of javascript. Please have a look for the html part

    <html>
    <head>
    <script type="text/javascript" src="ZeroClipboard.js"></script>
    </head>
    <body>
    <textarea name="copy-content" id="copy-content" rows="7" cols="60">
        We are sharing the script of copy in clipborad
    </textarea>
    <p><input type="button" id="copytoboard" name="copytoboard" value="Copy to Clipboard" /></p>
    </body>
    </html>
    

    You can use the library functions as follows.

    //set path
    ZeroClipboard.setMoviePath('http://findnerd.com/demo/ZeroClipboard.swf');
    
    //create client
    var clip = new ZeroClipboard.Client();
    
    //event
    clip.addEventListener('mousedown',function() {
        clip.setText(document.getElementById('copy-content').value);
    });
    clip.addEventListener('complete',function(client,text) {
        alert('copied: ' + text);
    });
    //glue it to the button
    clip.glue('"copytoboard');
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: