美文网首页
JS: copyToClipboard

JS: copyToClipboard

作者: 柳正来 | 来源:发表于2019-11-02 18:29 被阅读0次

    The following function is a handy util function that you can use to copy a string into clipboard.

    function copyToClipboard(str) {
      const el = document.createElement('textarea');
      el.value = str;
      el.setAttribute('readonly', '');
      el.style.position = 'absolute';
      el.style.left = '-9999px';
      document.body.appendChild(el);
      el.select();
      document.execCommand('copy');
      document.body.removeChild(el);
    };
    

    Reference

    相关文章

      网友评论

          本文标题:JS: copyToClipboard

          本文链接:https://www.haomeiwen.com/subject/nsdhbctx.html