flotilla/src/lib/html.ts

16 lines
359 B
TypeScript
Raw Normal View History

2024-08-08 23:32:46 +00:00
export const copyToClipboard = (text: string) => {
const {activeElement} = document
const input = document.createElement("textarea")
input.innerHTML = text
document.body.appendChild(input)
input.select()
const result = document.execCommand("copy")
document.body.removeChild(input)
;(activeElement as HTMLElement).focus()
return result
}