26 lines
597 B
JavaScript
26 lines
597 B
JavaScript
|
|
/**
|
||
|
|
* 复制到剪切板
|
||
|
|
*/
|
||
|
|
|
||
|
|
export function copyToClipboard(content) {
|
||
|
|
const clipboardData = window.clipboardData
|
||
|
|
if (clipboardData) {
|
||
|
|
clipboardData.clearData()
|
||
|
|
clipboardData.setData('Text', content)
|
||
|
|
return true
|
||
|
|
} else if (document.execCommand) {
|
||
|
|
const el = document.createElement('textarea')
|
||
|
|
el.value = content
|
||
|
|
el.setAttribute('readonly', '')
|
||
|
|
el.style.position = 'absolute'
|
||
|
|
el.style.left = '-9999px'
|
||
|
|
document.body.appendChild(el)
|
||
|
|
el.select()
|
||
|
|
document.execCommand('copy')
|
||
|
|
document.body.removeChild(el)
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
return false
|
||
|
|
|
||
|
|
}
|