An interesting and also slightly creepy approach to the problem is the JavaScript library Zero Clipboard:

The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface. The “Zero” signifies that the library is invisible and the user interface is left entirely up to you.

This library is fully compatible with Flash Player 10, which requires that the clipboard copy operation be initiated by a user click event inside the Flash movie. This is achieved by automatically floating the invisible movie on top of a DOM element of your choice. Standard mouse events are even propagated out to your DOM element, so you can still have rollover and mouse down effects.

Ha, yes, ZeroClipboard does work great. Unfortunately it’s a bit limited when you want to bind many instances of the tool to multiple text nodes. I posted a question on Stack Overflow just yesterday about this particular problem, but I’ve yet to find a better solution.

Here’s the code to use multiple text nodes with ZeroClipboard. As you can see, the code is quite redundant.

I just want to give my kudos to Joe for writing this library. We now use it on Yamli.com, and he’s probably saved me a couple of days of tearing my hair out.

It’s unfortunate that we have to resort to these methods to access the clipboard. It would be nice if the browsers did allow writing to the clipboard directly, perhaps as in Flash 10 only in response to a user click.