Oneezy
Oneezy

Reputation: 5013

How to click on an element and use javascripts "copy" event to add to the clipboard

Javascript finally has the "copy" event and we no longer have to use flash! (well, we still should use flash as a fallback).

http://dev.w3.org/2006/webapi/clipops/#x3.1.1-copy-event

I'm trying to figure out how to: Click on an anchor tag (Copy) and it copies the (text input src /or innerHTML) to the clipboard. Here's a fiddle of the HTML/CSS http://jsfiddle.net/LkUhM/

Can anyone guide me?

:::::HTML:::::

<div>
<ul>
    <li><input type="text" class="input" value="This is the next that will be copied!" /><a href="#" id="copy" class="copy">Copy!</a></li>
    <li><input type="text" class="input" value="This is the next that will be copied!" /><a href="#" id="copy" class="copy">Copy!</a></li>
    <li><input type="text" class="input" value="This is the next that will be copied!" /><a href="#" id="copy" class="copy">Copy!</a></li>
    <li><input type="text" class="input" value="This is the next that will be copied!" /><a href="#" id="copy" class="copy">Copy!</a></li>
</ul>

<textarea></textarea>

Upvotes: 0

Views: 493

Answers (1)

James M. Greene
James M. Greene

Reputation: 1311

  1. You're looking at an old version of that spec. The new one is here: http://www.w3.org/TR/clipboard-apis/
  2. According to the current spec, you cannot programmatically simulate any of these clipboard events. I am trying to work with the appropriate W3C working group to get that changed to at least allow simulation when the user clicks and/or issues a keyboard event (just like how you can get write access to the clipboard with Flash).

Upvotes: 1

Related Questions