Have ideas to improve npm?Join in the discussion! »

copy-text-to-clipboard
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

copy-text-to-clipboard

Copy text to the clipboard in modern browsers (0.2 kB)

Try it out!

Comparison

Install

$ npm install copy-text-to-clipboard

Usage

import copy from 'copy-text-to-clipboard';

button.addEventListener('click', () => {
	copy('🦄🌈');
});

API

copy(text, options?)

Copy text to the clipboard.

Returns a boolean of whether it succeeded to copy the text.

Must be called in response to a user gesture event, like click or keyup.

options

Type: object

target

Type: HTMLElement
Default: document.body

Specify a DOM element where the temporary, behind-the-scenes textarea should be appended, in cases where you need to stay within a focus trap, like in a modal.

Related

  • clipboardy - Access the system clipboard (copy/paste) in Node.js

Install

npm i copy-text-to-clipboard

DownloadsWeekly Downloads

118,846

Version

3.0.1

License

MIT

Unpacked Size

4.97 kB

Total Files

5

Last publish

Collaborators

  • avatar