# ivyforms/1.0/frontend/src/utils/clipboard.ts

The Innovative Form Builder – IvyForms, version 1.0. 30 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/1.0/code/frontend/src/utils/clipboard.ts
- Raw: https://pluginprobe.com/plugins/ivyforms/1.0/raw/frontend/src/utils/clipboard.ts
- Modified: 2026-05-06T08:31:02+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/1.0/code/frontend/src/utils/clipboard.ts#L10-L20`.

```typescript
export async function copyTextToClipboard(text: string): Promise<boolean> {
  if (typeof window === 'undefined' || typeof document === 'undefined') {
    return false
  }

  if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
    try {
      await navigator.clipboard.writeText(text)
      return true
    } catch {
      // Fall through to legacy fallback
    }
  }

  const textarea = document.createElement('textarea')
  textarea.value = text
  textarea.style.position = 'fixed'
  textarea.style.opacity = '0'
  document.body.appendChild(textarea)
  textarea.select()

  try {
    return document.execCommand('copy')
  } catch {
    return false
  } finally {
    textarea.remove()
  }
}

```
