Skip to content
Projetos

sindresorhus/copy-text-to-clipboard

Ver no GitHub

Sobre

Copia texto para a área de transferência em navegadores modernos (0,2 kB)

Outros projetos

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
+1
em 15 dias
+1
em 1 mês
0

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

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.

Related

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

Explore projetos relacionados

Carregando…