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

2.0.0 • Public • Published

clipboard-text Build Status npm package

Simple and small copy-text-to-the-clipboard-utility with IE11 support

Installation

npm install clipboard-text

Usage

import copy from 'clipboard-text'

button.addEventListener('click', () => {
  copy('Hi there')
})

API

copy(text: string, parentElement?: Element): boolean

Copy text to the clipboard.

If the event triggering the copy functions comes from an element with a focus trap, like a Modal, you will need to provide a parentElement. By default, parentElement is set to body.

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.

Related

License

MIT

Package Sidebar

Install

npm i clipboard-text

Weekly Downloads

11

Version

2.0.0

License

MIT

Unpacked Size

5.67 kB

Total Files

8

Last publish

Collaborators

  • posva