Answers for "js copy from clipboard"

26

javascript text to clipboard

function copyToClipboard(text) {
   const elem = document.createElement('textarea');
   elem.value = text;
   document.body.appendChild(elem);
   elem.select();
   document.execCommand('copy');
   document.body.removeChild(elem);
}
Posted by: Guest on March-20-2020
11

js copy text to clipboard

function copy() {
  var copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

document.querySelector("#copy").addEventListener("click", copy);
Posted by: Guest on September-17-2019
2

node.js copy to clipboard

// Copy to clipboard in node.js
const child_process = require('child_process')

// This uses an external application for clipboard access, so fill it in here
// Some options: pbcopy (macOS), xclip (Linux or anywhere with Xlib)
const COPY_APP = 'xclip'
function copy(data, encoding='utf8') {
  const proc = child_process.spawn(COPY_APP)
  proc.stdin.write(data, {encoding})
  proc.stdin.end()
}
Posted by: Guest on April-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language