Copy-to-Clipboard on a DOM element
Last updated 6 years ago by tootallnate .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install clipboard-dom 
SYNC missed versions from official npm registry.


Makes a DOM element (i.e. <button>) write to the system clipboard. This component is based off of the ZeroClipboard project, and in fact uses the same SWF Flash code.


$ component install component/clipboard-dom


    <!-- The "copy-button" *should* be inside a div with "position: relative"
         or something else that "has layout". -->
    <div style="position: relative;">
      <button id="copy-button">Copy to Clipboard</button>
    <script src="build/build.js"></script>
    <script src="main.js"></script>
// main.js

var Clip = require('clipboard-dom');

// set the path to the swf file first

// create a "Clip" instance
var ele = document.getElementById('copy-button');
var parent = ele.parentNode; // parent should "have layout"
var clip = new Clip(ele, parent);

// listen for meaningful events
clip.on('load', function(){
  console.log('button loaded');

clip.on('complete', function(text){
  console.log('copied text to the clipboard:', text);

clip.on('mousedown', function() {
  // "mousedown" is the last chance to set the text before it gets copied
  var input = document.getElementById('copy-text');



Fired when the SWF movie for the clipboard instance has loaded.


Fired when the user clicks on the button and the text has been copied. The text that got copied is passed in as an argument.


Fired when the user mouses over the button.


Fired when the user mouses away from the button.


Fired when the user pressed the mouse down on the button.


Fired when the user releases the mouse from the button.

Current Tags

  • 0.0.6                                ...           latest (6 years ago)

5 Versions

  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           8 years ago
  • 0.0.2                                ...           8 years ago

Copyright 2014 - 2016 © |