项目
在 GitHub 查看
sindresorhus/copy-text-to-clipboard
关于
在现代浏览器中将文本复制到剪贴板(0.2 kB)
其他项目实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 0
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文copy-text-to-clipboard
Copy text to the clipboard in modern browsers (0.2 kB)
Comparison
- This module: 0.2 kB
clipboard.js: 3.4 kB
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
探索相关项目
加载中…