16 lines
571 B
TypeScript
16 lines
571 B
TypeScript
/** Copie du texte dans le presse-papiers avec fallback pour HTTP non-localhost. */
|
|
export async function copyToClipboard(text: string): Promise<void> {
|
|
if (navigator.clipboard) {
|
|
await navigator.clipboard.writeText(text)
|
|
return
|
|
}
|
|
// Fallback : execCommand (HTTP non sécurisé)
|
|
const el = document.createElement('textarea')
|
|
el.value = text
|
|
el.style.cssText = 'position:fixed;top:-9999px;left:-9999px;opacity:0'
|
|
document.body.appendChild(el)
|
|
el.select()
|
|
document.execCommand('copy')
|
|
document.body.removeChild(el)
|
|
}
|