Socket
Socket
Sign inDemoInstall

clipboard-button

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    clipboard-button

Copy text to clipboard by clicking a button, using only vanilla javascript without Flash.


Version published
Weekly downloads
5
increased by150%
Maintainers
1
Install size
10.3 kB
Created
Weekly downloads
 

Readme

Source

clipboard-button

Build Status Test Coverage

Copy text to clipboard by clicking a button, using only vanilla javascript without Flash. This is using the new Selection API and Clipboard API available in the latest browsers.

Browser support: Chrome 43+, Firefox 41+, Opera 29+ and IE10+.

See the demo.

Install

Install using npm or bower:

$ npm install clipboard-button --save
$ bower install clipboard-button --save

clipboard-button has no dependencies.

Usage

Create a button on your page, and specify the text you want to copy in the data-clipboard-text attribute:

<button id="myButton" data-clipboard-text="textToCopy">Copy</button>

Initialize clipboard-button by specifying a target button, either by a selector string or element instance:

function success() {
    console.log('Copied!');
};

function fail(err) {
    console.error('Error!', err);
};

var cpb = clipboardButton('#myButton', success, fail);

You can supply optional callback methods to be called for the success and error event. The error function will be called with the error object as first argument.

To clean up all event handlers and resources, you can call cpb.destroy().

To detect whether the browser is supported you can check the static property clipboardButton.supported.

Keywords

FAQs

Last updated on 18 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc