Sunday 14 February 2010

Access the clipboard in Javascript

Now here is a wee something I fell over the other day whislt trying to figure out a way of copy and pasting a text stream from a Turd© document to a text area on a form. It would be really useful to grab the clipboard contents .. do some RegExp replaces on it and then import it into the text area.

Well after a moment or two's research you can be done in IE and you have to tweak Moz browsers see here to allow it to work and on Chrome it doesn't work

function clipboardHack ()
{
     var content = clipboardData.getData("Text");
     alert(content);
}

You can also push any changes back using clipboardData.setData("Text",[changedtext]);

Disqus for Domi-No-Yes-Maybe