Simon Harriyott

JavaScript clipboard control

I'm really not sure I like what I've just found. I noticed in the Visual Studio help that there is a "copy code" link, which eventually calls:

window.clipboardData.setData("Text", "some text for the clipboard");

That's fine from a clearly labelled link, but it also works from a <script> block, and in the IE address bar. I'm almost tempted to add it to this page, so you can try it, but I wouldn't want to replace whatever's in your clipboard without warning. There's plenty of people that would though.

Guess what the getData function does? It grabs what is already in the clipboard. Again, this can be run in a script block, which will happen when the page loads. This can then easily be posted to a server. I wonder how many times that has happened to me. You can see it in action by copying some text, and clicking the link. I won't post it anywhere.

Show clipboard contents

Scary huh?

[Update: more details on my later post]

12 January 2005