clipboard.ts 473 B

123456789101112131415161718
  1. /**
  2. * Copies a given string to the clipboard using
  3. * the legacy exec method
  4. *
  5. * @param content The content to be copied
  6. */
  7. export function copyToClipboard(content: string) {
  8. if (navigator.clipboard) {
  9. navigator.clipboard.writeText(content)
  10. } else {
  11. const dummy = document.createElement("textarea")
  12. document.body.appendChild(dummy)
  13. dummy.value = content
  14. dummy.select()
  15. document.execCommand("copy")
  16. document.body.removeChild(dummy)
  17. }
  18. }