Cross Browser Copy and Paste - with ZeroClipboard *updated*

Some thoughts scribbled down on Monday 25 January 2010 at 08:09 PM

I previously wrote about a cross browser copy and paste using jQuery.Copy. Everything was fine until flash updated to version 10. It now throws a security warning. Jojo pointed out that were was another plugin using the same concept that avoids this security warning. Enter Zero Clipboard The implementation is simple:

Step 1 - Include ZeroClipboard.js & ZeroClipboard.swf

Include ZeroClipboard.js in your header scripts. After the script, set the path of the ZeroClipboard.swf flash file.

<head>
	...
	<script type="text/javascript" src="/scripts/ZeroClipboard.js"></script>
</head>

<script type="text/javascript">
	ZeroClipboard.setMoviePath('/scripts/ZeroClipboard.swf');
</script>

Step 2 - Start using it!

ZeroClipboard allows you to create multiple instances of the clipboard. In most circumstances you will only need one. Instantiate the clipboard and then start using it.

	var clip = new ZeroClipboard.Client();

	// Copy some text
	clip.setText("Hello World");

There's a lot more you can do with this little script and you can find out more from their wiki

Comments

There are currently no comments.

Post your comment