W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2015

Re: [clipops][editing] document.execCommand('copy', false, 'some data') ?

From: Daniel Cheng <dcheng@chromium.org>
Date: Fri, 10 Apr 2015 20:55:22 +0000
Message-ID: <CAF3XrKq5BFpEgSz-iK0egGx6A0MSDYnFvL4sZo7bPjxqCogNEQ@mail.gmail.com>
To: Hallvord Reiar Michaelsen Steen <hsteen@mozilla.com>, WebApps WG <public-webapps@w3.org>
1) I was under the impression (and MDN supports this) that the value
argument for execCommand() must be a DOMString. Has that changed?

2) How would a supplied value interact with existing copy/cut handlers?

Daniel

On Fri, Apr 10, 2015 at 5:16 AM Hallvord Reiar Michaelsen Steen <
hsteen@mozilla.com> wrote:

> It's pretty obvious that the currently spec'ed code for "place 'foo' on
> the clipboard when user clicks my <button>"  is not nice at all. Per  [1]
> the code you need now is more or less
>
> document.addEventListener('copy', function(e){
>   e.clipboardData.setData('text/plain', 'foo');
>   e.preventDefault(); // default behaviour is to copy any selected text
> }
> element.onclick = function(){
>   document.execCommand('copy', false, ''); // only works in click handler
> or other user-triggered thread
> }
>
> There is a very annoying disconnect between the code that knows what the
> user clicked and the code that actually places content on the clipboard.
> This requires rather poor hacks and workarounds like having global
> variables (or variables in a closure both functions can access) for storing
> data temporarily.
>
> However, document.execCommand() is spec'ed as having a "value" argument.
> What about actually using it here? Simplifying the above code to:
>
> element.onclick = function(){
>     document.execCommand('copy', false, 'foo');
> }
>
> If we wanted to get fancy, we could even allow
>
> element.onclick = function(){
>     document.execCommand('copy', false, {'text/plain': 'foo',
> 'text/html':'<p><b>foo</b></p>'});
> }
>
> Thoughts?
>
> [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1151429#c2
>
Received on Friday, 10 April 2015 20:55:51 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:27:31 UTC