Skip to content

andmetoo/copy-to-clipboard

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Copy to clipboard

Simple module exposing copy(input: text) function that would try to use execCommand with fallback to IE specific clipboardData interface and finally, fallback to simple prompt with proper text content & 'Copy to clipboard: Ctrl+C, Enter'

Example

import copy from 'copy-to-clipboard';

copy('Text');

# Copy with options
copy('Text', {
  debug: true,
  message: 'Press ⌘-C to copy',
});

API

copy(input: text, options) - tries to copy text to clipboard.

Value Default Notes
options.debug false Boolean. Optional. Enable output to console.
options.message Copy to clipboard: Ctrl+C, Enter String. Optional. Prompt message.

* - for Mac OS users message features instead of Ctrl

Works everywhere where there's prompt available. Works best (i.e. without additional keystrokes) in Chrome, FF and, supposedly, IE.

Note: not working on some older IOS devices

Installation

  • Can be used as npm package and then leveraged using commonjs bundler/loader.
npm i --save copy-to-clipboard
  • Can be utilized using wzrd.in. After adding following script to your page
<script src='https://wzrd.in/standalone/copy-to-clipboard@latest'></script>

You will have window.copyToClipboard exposed for you to use

UI components based on this package:

See also

About

Copy stuff into clipboard using JS

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%