Connect with me
Search
Twitter Feed
Navigation
« Getting the physical folder path of a virtual path or directory in WCF | Main | datejs - the javascript date library that will let you work with dates like a ninja »
Monday
Jan252010

Cross Browser Copy and Paste - with ZeroClipboard *updated*

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-

Reader Comments (5)

is it working with ie8 ?

22 September 2010 | Unregistered Commenterratheesh

does this work in ie7?

25 October 2011 | Unregistered Commenterdriver cpc training

what about ie6, does it work in that?

08 December 2011 | Unregistered Commenterderk

Hello,

I am trying to implement same logic for the <pre> implementation as you - syntax highlighting and copy etc. functionality.

Would you please share / write a blog post on how to accomplish that?

Regards,
Hasan Ceylan

16 January 2012 | Unregistered CommenterHasan Ceylan

@ratheesh, @driver cpc training, @derk updated the post to include the compatibility matrix

24 January 2012 | Registered CommenterEric Phan

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>