Skip to content

copyText

copyText(text): Promise<boolean>

复制文本到剪贴板

将指定文本复制到系统剪贴板

Parameters

NameTypeDescription
textstring要复制的文本

Returns

Promise<boolean>

Promise,成功时返回 true,失败时返回 false

Example

ts
// 基本用法
copyText('Hello, world!').then(success => {
  if (success) {
    console.log('文本已复制到剪贴板');
  } else {
    console.error('复制失败');
  }
});

// 在按钮点击事件中使用
button.addEventListener('click', () => {
  copyText('要复制的文本');
});

Released under the MIT License.