Copy to clipboard using javascript(Zeroclipboard)

I tried so many ways to implement this, but found the below snippet very useful(using zeroclipboard.js)

<html>
<body>
<script type=”text/javascript” src=”ZeroClipboard.js”></script>
<script type=”text/javascript”>
//set path
ZeroClipboard.setMoviePath(‘ZeroClipboard.swf’);
//create client
var clip = new ZeroClipboard.Client();
//event

clip.setHandCursor( true );

clip.addEventListener(‘mousedown’, function () {
clip.setText(document.getElementById(‘box-content’).value);
});
clip.addEventListener(‘complete’, function (client, text) {
alert(‘copied: ‘ + text);
});
//glue it to the button
clip.glue(‘copy’);
</script>

<textarea name=”box-content” id=”box-content” rows=”5″ cols=”70″>
Amit Mohanty Blog is the best blog around! 
</textarea>
<br />
<br />
<p>
<input type=”button” id=”copy” name=”copy” value=”Copy to Clipboard” />
</p>
</body>
</html>

Make sure to include both files Zeroclipboard.js and ZeroClipboard.swf

That’s it.

13 thoughts on “Copy to clipboard using javascript(Zeroclipboard)

  1. I truly love your website.. Pleasant colors & theme.
    Did you develop this amazing site yourself? Please
    reply back as I’m hoping to create my very own website and want to find out
    where you got this from or what the theme is called.

    Many thanks!

    Like

  2. I have been explooring for a little bit forr any high-quality
    articles or weblog posts on this sort of house .
    Exploring in Yahoo I at laast stumbled upon this website. Reading this info So i’m happy to exhibit
    that I have a very just right uncanny feeling I found out exactly what
    I needed. I such a lot indisputably will make sure
    to do not disregard this site and give it a look regularly.

    Like

  3. Hello superb website! Does running a blog similar to this require a lot of work?

    I have absolutely no expertise in computer programming
    but I had been hoping to start my own blog in the near future.
    Anyhow, if you have any suggestions or techniques for new blog owners please share.
    I know this is off topic however I just wanted
    to ask. Many thanks!

    Like

  4. Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is valuable and all. But think
    of if you added some great images or video clips to give your posts
    more, “pop”! Your content is excellent but with pics and video clips, this
    site could definitely be one of the most beneficial in its field.
    Awesome blog!

    Like

  5. Hello! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any recommendations?

    Like

Leave a reply to best diet for insulin resistance Cancel reply