Files
daywork/intern-log/src/lib/clipboard.ts
T

15 lines
380 B
TypeScript

export async function copyText(text: string): Promise<void> {
try {
await navigator.clipboard.writeText(text)
} catch {
const ta = document.createElement('textarea')
ta.value = text
ta.style.position = 'fixed'
ta.style.opacity = '0'
document.body.appendChild(ta)
ta.select()
document.execCommand('copy')
document.body.removeChild(ta)
}
}