Re: Broken links

> If my requirement is still unclear please try to read this question on 
> StackOverflow: http://stackoverflow.com/q/27206268/607407
> (http://stackoverflow.com/q/27206268/607407). It basically describes the 
> problem.

Hi Jakub, thanks for bringing this up - I've replied on StackOverflow, and it's a good reminder that what's in an editor's draft matters.

In the HTML5 spec, in the IDL declaration, the setData() method is underneath the comment /* old interface */. I suppose we could add a more obvious comment explaining that this API only handles strings and data that can be stringified.

To avoid moving a potential list conversation over to the StackOverflow website, excellent though it is, here's my full response from SO:

I'm the editor of the Clipboard APIs spec.

First, sorry about the broken link. It is actually working in the official TR:

http://www.w3.org/TR/clipboard-apis/

But not in the Editor's Draft, for somewhat messy process reasons (the "official" HTML5 spec dropped stuff the Clipboard API spec relies on, hard-coding a link to a specific historical snapshot of the official HTML5 spec seems like a bad idea - so I need to decide whether to simply link to the WHATWG spec or wait until a hypotethical HTML6-brings-DnD-back-in situation happens).

Now, fixing this link doesn't actually solve your problem - because even in the [supposedly bleeding-edge WHATWG spec][1], setData() is specified as taking a string. Web technology is a work in progress, and you've come across a use case that the (older) setData() API did not take into account. This part of the API dates back to the original Microsoft implementation To be fair, JavaScript itself didn't really have convenient ways to work with binary data back then..

What you probably want to use, is the [clipboardData.items.add() API][2] passing in [a File object][3] with the relevant data and type. Note that this isn't widely implemented yet, for example AFAIK it's not supported in any current version of Firefox. You can detect the lack of clipboardData.items and .items.add(), and for example tell users to right-click and image and choose "copy to clipboard" manually.

  [1]: https://html.spec.whatwg.org/multipage/interaction.html#the-datatransfer-interface
  [2]: https://html.spec.whatwg.org/multipage/interaction.html#dom-datatransferitemlist-add
  [3]: http://dev.w3.org/2006/webapi/FileAPI/#file

-Hallvord
(right now stuck in Iceland for weather reasons, but too focused on work to be in the Blue lagoon ;))

Received on Tuesday, 2 December 2014 11:29:17 UTC