OSDN Git Service

Merge Dashboard into Electron.
[bytom/bytom-electron.git] / src / utility / clipboard.js
1 // Assumes the presence of an input element with ID #_copyInput
2 export const copyToClipboard = value => {
3   const listener = e => {
4     e.clipboardData.setData('text/plain', value)
5     e.preventDefault()
6     document.removeEventListener('copy', listener)
7   }
8
9   // Required for Safari. Contents of selection are not used.
10   document.getElementById('_copyInput').select()
11
12   document.addEventListener('copy', listener)
13   document.execCommand('copy')
14 }