const 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)
      }

      Javascript language logo
      Copy text to Clipboard (old browsers)

      copy-text
      Javascript recipes

      The code creates a textarea and sets its value to the string "copy". It then positions the textareaabsolutely to the left of the document. It then selects the textarea and uses the execCommand() function to copy the content to the clipboard.

      Shortcut: CopyText

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.