1

Imagine I want a user to be able to copy-paste a selection of pixels from MSPaint into a browser-based app. Is this possible using JavaScript in any current browsers? Will it become possible in HTML5? If not, is it feasible using something like Flex/Silverlight, or is it simply not possible at this time, and you'd have to save a file and manually upload it?

update: sounds like HTML5 should allow it, but that's a way in the future to be genuinely useful. Some suggestions of Java applets and Flash are mentioned, probably Flash would be preferable since parts of the web-client would probably use Flex anyway... I'd rather not have requirement for Java and Flash in my site.

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • Not really an answer, but it's a step in the right direction, I'm sure: For inserting the data directly into html markup, see data URI scheme (wikipedia). Unfortunately, now you're stuck between the client's image on the clipboard and encoding it into a string you can insert in an image src. Unfortunately, outside of VB or Java or ActiveX (IWindows only), there's no way. – bob-the-destroyer Jun 18 '10 at 21:43
  • If I can get the data into the web-app, I can send it to the server and spit back an image of some sort... the big usability bonus is the user being able to copy-paste image data without having to save as a file themself and upload it. – Mr. Boy Jun 19 '10 at 11:56

1 Answers1

2

There's a very thorough examination of this prior question: Wysiwyg with image copy/paste. It discusses possibly coming behavior in HTML5, as well as Flash and Java applet solutions that interact with the clipboard, and which you can then tie into JavaScript.


Questioner asked about Zeroclipboard's applicability. So, look at the file ZeroClipboard10.as and you'll see the click handler supports two data formats:

private function clickHandler(event:Event):void {
    // user click copies text to clipboard
    // as of flash player 10, this MUST happen from an in-movie flash click event
    Clipboard.generalClipboard.clear();
    Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, clipText);
    Clipboard.generalClipboard.setData(ClipboardFormats.HTML_FORMAT, clipText);
    ExternalInterface.call( 'ZeroClipboard.dispatch', id, 'complete', clipText );
}

The reference for ActionScript's ClipboardFormats constant indicates one of the formats is a BITMAP_FORMAT. So I think that's a pretty good start.

Community
  • 1
  • 1
artlung
  • 33,305
  • 16
  • 69
  • 121
  • Thanks for the references. However I'm not clear how zeroclipboard is applicable, it talks about text and RTF. I'd love to see a discussion on the mechanics of how to get the contents of the system clipboard using Flash (using that library as a reference if applicable) – Mr. Boy Jun 17 '10 at 09:12
  • Updated with info on zeroclipboard! Hope that helps! – artlung Jun 17 '10 at 22:31
  • Those class references all say 'AIR only' and are part of flash.desktop. I think I'll give you the bounty, but maybe start a thread explicitly asking about Flash/Flex clipboards as well, on which your input is most welcome! Thanks. – Mr. Boy Jun 19 '10 at 11:53