Files
standardnotes-app-web/packages/web/src/javascripts/Utils/copyTextToClipboard.tsx

27 lines
633 B
TypeScript

export function fallbackCopyTextToClipboard(text: string) {
const textArea = document.createElement('textarea')
textArea.value = text
textArea.style.top = '0'
textArea.style.left = '0'
textArea.style.position = 'fixed'
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
try {
document.execCommand('copy')
} catch (err) {
console.error('Unable to copy', err)
}
document.body.removeChild(textArea)
}
export function copyTextToClipboard(text: string) {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(text)
return
}
void navigator.clipboard.writeText(text)
}