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)