1. copy-text-to-clipboard
Copy text to the clipboard in modern browsers (0.2 kB)
copy-text-to-clipboard
Package: copy-text-to-clipboard
Created by: sindresorhus
Last modified: Wed, 05 Jul 2023 22:01:35 GMT
Version: 3.2.0
License: MIT
Downloads: 1,528,971
Repository: https://github.com/sindresorhus/copy-text-to-clipboard

Install

npm install copy-text-to-clipboard
yarn add copy-text-to-clipboard

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.

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code