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

***EDIT***

Because a lot of people have been commenting about compatibility, here is the compatibility matrix from http://code.google.com/p/zeroclipboard/wiki/Instructions

Browser Support

The Zero Clipboard Library has been tested on the following browsers / platforms:

Browser Windows XP SP3 Windows Vista Mac OS X Leopard
Internet Exploder7.07.0-
Firefox3.03.03.0
Safari--3.0
Google Chrome1.01.0-

7 Comments