JavaScript MIT

copy-text-to-clipboard

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

S

sindresorhus

Dernière activité 18 sept. 2026
sindresorhus/copy-text-to-clipboard

1 k

étoiles

222

forks

0

issues ouvertes

Ce README est souvent en anglais.

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

Tip

Consider using navigator.clipboard.writeText(text) directly. Keep in mind that the native API requires a secure context (HTTPS). This package works in non-secure contexts too.

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.

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

Projets similaires

Modern copy to clipboard. No Flash. Just 3kb gzipped

JavaScriptclipboardjavascript
Zzenorocha
34,1 k étoiles3,9 k

Access the system clipboard (copy/paste)

JavaScript
Ssindresorhus
2 k étoiles71

Copy-to-clipboard React component

JavaScript
Nnkbt
2,4 k étoiles132