Re: [clipboard] Feature detect Clipboard API support?

On Wed, Feb 11, 2015 at 12:34 PM, Michaela Merz <michaela.merz@hermetos.com>
wrote:

>
> AFAIK, you can't trigger a clip board request without human interaction.
>
>  $('#element).off().on('click',function(e)     {
>     var clip = new ClipboardEvent('copy');
>     clip.clipboardData.setData('text/plain','some data');
>     clip.preventDefault();
>     e.target.dispatchEvent(clip);
>     });
>
> This unfortunately won't work in my environment since my code is not
> 'trusted'.
>

Events are used to detect that something happened, not to cause the thing
to happen.  The copy event tells you that a copy happened, you don't
dispatch "copy" to cause a copy to happen.  You use regular API calls to do
that, like execCommand("copy").  You're correct that you usually can't use
that except in response to a user action, of course.

-- 
Glenn Maynard

Received on Thursday, 12 February 2015 00:17:23 UTC