@ylz/plugins
Version:
ylz plugins
38 lines (35 loc) • 900 B
JavaScript
/**
* @description:
* @Date: 2019-05-22 13:37:02
*/
function getContainer() {
let $copy = document.getElementById('$copy')
if (!$copy) {
$copy = document.createElement('input')
$copy.id = '$copy'
$copy.style['width'] = '48px'
$copy.style['height'] = '12px'
$copy.style['position'] = 'fixed'
$copy.style['z-index'] = '0'
$copy.style['left'] = '-500px'
$copy.style['top'] = '-500px'
document.body.appendChild($copy)
}
return $copy
}
function XEClipboard(content) {
const $copy = getContainer()
const value = content === null || content === undefined ? '' : '' + content
try {
$copy.value = value
$copy.focus()
$copy.setSelectionRange(0, value.length)
const copySty = document.execCommand('copy', true)
document.body.removeChild($copy)
return copySty
} catch (e) {}
return false
}
export default {
copy: XEClipboard
}