sheng-tool
    Preparing search index...

    Function copyText

    • 复制文本。

      现代浏览器优先使用 navigator.clipboard.writeText;不可用时退回到隐藏 textarea 和 document.execCommand('copy')。 如果运行环境没有 Promise,需要调用方自行提供 Polyfill。

      Parameters

      • text: string

        被复制的文本

      Returns Promise<void>

      文本写入剪贴板后的 Promise

      0.0.21

      (async () => {
      const text = await copyText('hello world');
      // 此时按 Ctrl / Command + V 即可粘贴「hello world 文本」
      }